finished tradingeconomics i think
This commit is contained in:
parent
748cce0eeb
commit
167a586257
10 changed files with 658 additions and 233 deletions
|
|
@ -0,0 +1,41 @@
|
|||
import type { TeHandler } from '../te.handler';
|
||||
|
||||
export async function dataScheduler(this: TeHandler): Promise<{ scheduled: number }> {
|
||||
const { logger, mongodb } = this;
|
||||
|
||||
const candidates = await mongodb?.find('teUrls', {
|
||||
teType: 'te',
|
||||
teSymbol: { $exists: true, $ne: null },
|
||||
teChartsDatasource: { $exists: true },
|
||||
teChartToken: { $exists: true },
|
||||
teLastUpdate: { $exists: true },
|
||||
teChart: 'EC',
|
||||
$or: [
|
||||
{ lastDataFetch: { $exists: false } },
|
||||
{ $expr: { $ne: ['$teLastUpdate', '$lastDataFetchUpdate'] } },
|
||||
],
|
||||
}, {
|
||||
sort: { lastDataFetch: 1 },
|
||||
projection: { teSymbol: 1, url: 1, lastDataFetch: 1 },
|
||||
});
|
||||
|
||||
if (!candidates?.length) {
|
||||
logger.debug('No symbols need data fetching');
|
||||
return { scheduled: 0 };
|
||||
}
|
||||
|
||||
logger.info(`Scheduling ${candidates.length} symbols for TE data fetch`);
|
||||
|
||||
for (const doc of candidates) {
|
||||
await this.scheduleOperation('te-data-fetch', {
|
||||
teSymbol: doc.teSymbol,
|
||||
url: doc.url,
|
||||
isInitialFetch: !doc.lastDataFetch,
|
||||
}, {
|
||||
jobId: `data-fetch-${doc.teSymbol}`,
|
||||
priority: 8,
|
||||
});
|
||||
}
|
||||
|
||||
return { scheduled: candidates.length };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue