standartized OperationTracker. need to test it all out now

This commit is contained in:
Boki 2025-07-01 11:15:33 -04:00
parent f78558224f
commit 680b5fd2ae
21 changed files with 2112 additions and 752 deletions

View file

@ -5,23 +5,8 @@
import type { ExecutionContext } from '@stock-bot/handlers';
import type { QMHandler } from '../qm.handler';
import { QM_CONFIG, QM_SESSION_IDS } from '../shared/config';
import { QMOperationTracker } from '../shared/operation-tracker';
import { QMSessionManager } from '../shared/session-manager';
// Cache tracker instance
let operationTracker: QMOperationTracker | null = null;
/**
* Get or initialize the operation tracker
*/
async function getOperationTracker(handler: QMHandler): Promise<QMOperationTracker> {
if (!operationTracker) {
const { initializeQMOperations } = await import('../shared/operation-registry');
operationTracker = await initializeQMOperations(handler.mongodb, handler.logger);
}
return operationTracker;
}
/**
* Update financials for a single symbol
*/
@ -105,8 +90,7 @@ export async function updateFinancials(
);
// Update symbol to track last financials update
const tracker = await getOperationTracker(this);
await tracker.updateSymbolOperation(qmSearchCode, `financials_${reportType === 'Q'? 'quarterly' : 'annual'}_update`, {
await this.operationRegistry.updateOperation('qm', qmSearchCode, `financials_update_${reportType === 'Q'? 'quarterly' : 'annual'}`, {
status: 'success',
lastRecordDate: new Date(),
recordCount: reports.length
@ -144,8 +128,7 @@ export async function updateFinancials(
});
// Track failure
const tracker = await getOperationTracker(this);
await tracker.updateSymbolOperation(qmSearchCode, 'financials_update', {
await this.operationRegistry.updateOperation('qm', qmSearchCode, `financials_update_${reportType === 'Q'? 'quarterly' : 'annual'}`, {
status: 'failure',
});
@ -173,17 +156,16 @@ export async function scheduleFinancialsUpdates(
errors: number;
}> {
const { limit = 100000, forceUpdate = false } = input;
const tracker = await getOperationTracker(this);
this.logger.info('Scheduling financials updates', { limit, forceUpdate });
try {
// Get symbols that need updating for both quarterly and annual
const staleSymbolsQ = await tracker.getStaleSymbols('financials_quarterly_update', {
const staleSymbolsQ = await this.operationRegistry.getStaleSymbols('qm', 'financials_update_quarterly', {
minHoursSinceRun: forceUpdate ? 0 : 24 * 7, // Weekly by default
limit
});
const staleSymbolsA = await tracker.getStaleSymbols('financials_annual_update', {
const staleSymbolsA = await this.operationRegistry.getStaleSymbols('qm', 'financials_update_annual', {
minHoursSinceRun: forceUpdate ? 0 : 24 * 7, // Weekly by default
limit
});