From dcc5ffe790cc5e4890efa35f83b9dbc09907829d Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Wed, 4 Sep 2024 21:07:59 +0200 Subject: [PATCH] Refactoring --- .../data-provider/manual/manual.service.ts | 27 +++++++++---------- .../symbol-profile/symbol-profile.service.ts | 2 ++ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/apps/api/src/services/data-provider/manual/manual.service.ts b/apps/api/src/services/data-provider/manual/manual.service.ts index be8e467cb..02e50a145 100644 --- a/apps/api/src/services/data-provider/manual/manual.service.ts +++ b/apps/api/src/services/data-provider/manual/manual.service.ts @@ -166,27 +166,26 @@ export class ManualService implements DataProviderInterface { } }); - const symbolProfilesWithScraperConfiguration = symbolProfiles.filter( - ({ scraperConfiguration }) => { - return !!scraperConfiguration?.url; - } - ); + const symbolProfilesWithScraperConfigurationAndInstantMode = + symbolProfiles.filter(({ scraperConfiguration }) => { + return scraperConfiguration?.mode === 'instant'; + }); - const scraperResultPromises = symbolProfilesWithScraperConfiguration.map( - ({ scraperConfiguration, symbol }) => { - return this.scrape(scraperConfiguration) - .then((marketPrice) => { + const scraperResultPromises = + symbolProfilesWithScraperConfigurationAndInstantMode.map( + async ({ scraperConfiguration, symbol }) => { + try { + const marketPrice = await this.scrape(scraperConfiguration); return { marketPrice, symbol }; - }) - .catch((error) => { + } 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); diff --git a/apps/api/src/services/symbol-profile/symbol-profile.service.ts b/apps/api/src/services/symbol-profile/symbol-profile.service.ts index 50cb25000..283da7b52 100644 --- a/apps/api/src/services/symbol-profile/symbol-profile.service.ts +++ b/apps/api/src/services/symbol-profile/symbol-profile.service.ts @@ -275,6 +275,8 @@ export class SymbolProfileService { headers: scraperConfiguration.headers as ScraperConfiguration['headers'], locale: scraperConfiguration.locale as string, + mode: + (scraperConfiguration.mode as ScraperConfiguration['mode']) ?? 'lazy', selector: scraperConfiguration.selector as string, url: scraperConfiguration.url as string };