diff --git a/apps/stock/data-ingestion/src/handlers/qm/actions/symbol.action.ts b/apps/stock/data-ingestion/src/handlers/qm/actions/symbol.action.ts index 31481dd..3741526 100644 --- a/apps/stock/data-ingestion/src/handlers/qm/actions/symbol.action.ts +++ b/apps/stock/data-ingestion/src/handlers/qm/actions/symbol.action.ts @@ -73,11 +73,10 @@ export async function spiderSymbol( // Extract and store unique exchanges const exchanges: Exchange[] = []; for (const symbol of symbols) { - if (symbol.exchange && !exchanges.some(ex => ex.exchange === symbol.exchange)) { + if (symbol.exchangeCode && !exchanges.some(ex => ex.exchange === symbol.exchangeCode)) { exchanges.push({ - exchange: symbol.exchange, - exchangeCode: symbol.exchangeCode || '', - exchangeShortName: symbol.exchangeShortName || '', + exchange: symbol.exchangeCode, + exchangeName: symbol.exchangeShortName || '', countryCode: symbol.countryCode || '', source: 'qm', }); diff --git a/apps/stock/data-ingestion/src/handlers/qm/shared/operation-tracker.ts b/apps/stock/data-ingestion/src/handlers/qm/shared/operation-tracker.ts index a7c3c79..1ab6f72 100644 --- a/apps/stock/data-ingestion/src/handlers/qm/shared/operation-tracker.ts +++ b/apps/stock/data-ingestion/src/handlers/qm/shared/operation-tracker.ts @@ -101,6 +101,11 @@ export class QMOperationTracker { } }; + // Only update lastSuccessAt on successful operations + if (data.status === 'success') { + update.$set[`operations.${operationName}.lastSuccessAt`] = new Date(); + } + if (data.lastRecordDate) { update.$set[`operations.${operationName}.lastRecordDate`] = data.lastRecordDate; } @@ -151,6 +156,11 @@ export class QMOperationTracker { } }; + // Only update lastSuccessAt on successful operations + if (data.status === 'success') { + update.$set[`operations.${operation}.lastSuccessAt`] = new Date(); + } + if (data.lastRecordDate) { update.$set[`operations.${operation}.lastRecordDate`] = data.lastRecordDate; } @@ -208,8 +218,8 @@ export class QMOperationTracker { const filter: any = { $or: [ - { [`operations.${operationName}.lastRunAt`]: { $lt: cutoffDate } }, - { [`operations.${operationName}.lastRunAt`]: { $exists: false } }, + { [`operations.${operationName}.lastSuccessAt`]: { $lt: cutoffDate } }, + { [`operations.${operationName}.lastSuccessAt`]: { $exists: false } }, { [`operations.${operationName}`]: { $exists: false } } ] }; @@ -221,7 +231,7 @@ export class QMOperationTracker { const symbols = await this.mongodb.find(this.collectionName, filter, { limit, projection: { qmSearchCode: 1 }, - sort: { [`operations.${operationName}.lastRunAt`]: 1 } // Oldest first + sort: { [`operations.${operationName}.lastSuccessAt`]: 1 } // Oldest successful run first }); return symbols.map(s => s.qmSearchCode); diff --git a/apps/stock/data-ingestion/src/handlers/qm/shared/types.ts b/apps/stock/data-ingestion/src/handlers/qm/shared/types.ts index de52fcc..eba642b 100644 --- a/apps/stock/data-ingestion/src/handlers/qm/shared/types.ts +++ b/apps/stock/data-ingestion/src/handlers/qm/shared/types.ts @@ -21,8 +21,7 @@ export interface SymbolSpiderJob { export interface Exchange { exchange: string; - exchangeCode: string; - exchangeShortName: string; + exchangeName: string; countryCode: string; source: string; }