Feature/execute scraper configuration instantly (#3723)
* Execute scraper configuration instantly * Update changelog --------- Co-authored-by: Thomas Kaul <4159106+dtslvr@users.noreply.github.com>
This commit is contained in:
parent
8018236942
commit
7ea9061852
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Set up a performance logging service
|
- Set up a performance logging service
|
||||||
|
- Added the attribute `mode` to the scraper configuration to get quotes instantly
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
@ -166,11 +166,42 @@ export class ManualService implements DataProviderInterface {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const symbolProfilesWithScraperConfigurationAndInstantMode =
|
||||||
|
symbolProfiles.filter(({ scraperConfiguration }) => {
|
||||||
|
return scraperConfiguration?.mode === 'instant';
|
||||||
|
});
|
||||||
|
|
||||||
|
const scraperResultPromises =
|
||||||
|
symbolProfilesWithScraperConfigurationAndInstantMode.map(
|
||||||
|
async ({ scraperConfiguration, symbol }) => {
|
||||||
|
try {
|
||||||
|
const marketPrice = await this.scrape(scraperConfiguration);
|
||||||
|
return { marketPrice, symbol };
|
||||||
|
} catch (error) {
|
||||||
|
Logger.error(
|
||||||
|
`Could not get quote for ${symbol} (${this.getName()}): [${error.name}] ${error.message}`,
|
||||||
|
'ManualService'
|
||||||
|
);
|
||||||
|
return { symbol, marketPrice: undefined };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Wait for all scraping requests to complete concurrently
|
||||||
|
const scraperResults = await Promise.all(scraperResultPromises);
|
||||||
|
|
||||||
for (const { currency, symbol } of symbolProfiles) {
|
for (const { currency, symbol } of symbolProfiles) {
|
||||||
let marketPrice =
|
let { marketPrice } =
|
||||||
|
scraperResults.find((result) => {
|
||||||
|
return result.symbol === symbol;
|
||||||
|
}) ?? {};
|
||||||
|
|
||||||
|
marketPrice =
|
||||||
|
marketPrice ??
|
||||||
marketData.find((marketDataItem) => {
|
marketData.find((marketDataItem) => {
|
||||||
return marketDataItem.symbol === symbol;
|
return marketDataItem.symbol === symbol;
|
||||||
})?.marketPrice ?? 0;
|
})?.marketPrice ??
|
||||||
|
0;
|
||||||
|
|
||||||
response[symbol] = {
|
response[symbol] = {
|
||||||
currency,
|
currency,
|
||||||
|
@ -275,6 +275,8 @@ export class SymbolProfileService {
|
|||||||
headers:
|
headers:
|
||||||
scraperConfiguration.headers as ScraperConfiguration['headers'],
|
scraperConfiguration.headers as ScraperConfiguration['headers'],
|
||||||
locale: scraperConfiguration.locale as string,
|
locale: scraperConfiguration.locale as string,
|
||||||
|
mode:
|
||||||
|
(scraperConfiguration.mode as ScraperConfiguration['mode']) ?? 'lazy',
|
||||||
selector: scraperConfiguration.selector as string,
|
selector: scraperConfiguration.selector as string,
|
||||||
url: scraperConfiguration.url as string
|
url: scraperConfiguration.url as string
|
||||||
};
|
};
|
||||||
|
@ -2,6 +2,7 @@ export interface ScraperConfiguration {
|
|||||||
defaultMarketPrice?: number;
|
defaultMarketPrice?: number;
|
||||||
headers?: { [key: string]: string };
|
headers?: { [key: string]: string };
|
||||||
locale?: string;
|
locale?: string;
|
||||||
|
mode?: 'instant' | 'lazy';
|
||||||
selector: string;
|
selector: string;
|
||||||
url: string;
|
url: string;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user