standartized OperationTracker. need to test it all out now
This commit is contained in:
parent
f78558224f
commit
680b5fd2ae
21 changed files with 2112 additions and 752 deletions
|
|
@ -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 filings for a single symbol
|
||||
*/
|
||||
|
|
@ -97,8 +82,7 @@ export async function updateFilings(
|
|||
);
|
||||
|
||||
// Update symbol to track last filings update
|
||||
const tracker = await getOperationTracker(this);
|
||||
await tracker.updateSymbolOperation(qmSearchCode, 'filings_update', {
|
||||
await this.operationRegistry.updateOperation('qm', qmSearchCode, 'filings_update', {
|
||||
status: 'success',
|
||||
lastRecordDate: new Date(),
|
||||
recordCount: filingsData.length
|
||||
|
|
@ -117,8 +101,7 @@ export async function updateFilings(
|
|||
};
|
||||
} else {
|
||||
// Some symbols may not have filings (non-US companies, etc)
|
||||
const tracker = await getOperationTracker(this);
|
||||
await tracker.updateSymbolOperation(qmSearchCode, 'filings_update', {
|
||||
await this.operationRegistry.updateOperation('qm', qmSearchCode, 'filings_update', {
|
||||
status: 'success',
|
||||
lastRecordDate: new Date(),
|
||||
recordCount: 0
|
||||
|
|
@ -145,8 +128,7 @@ export async function updateFilings(
|
|||
});
|
||||
|
||||
// Track failure
|
||||
const tracker = await getOperationTracker(this);
|
||||
await tracker.updateSymbolOperation(qmSearchCode, 'filings_update', {
|
||||
await this.operationRegistry.updateOperation('qm', qmSearchCode, 'filings_update', {
|
||||
status: 'failure'
|
||||
});
|
||||
|
||||
|
|
@ -174,13 +156,12 @@ export async function scheduleFilingsUpdates(
|
|||
errors: number;
|
||||
}> {
|
||||
const { limit = 100, forceUpdate = false } = input;
|
||||
const tracker = await getOperationTracker(this);
|
||||
|
||||
this.logger.info('Scheduling filings updates', { limit, forceUpdate });
|
||||
|
||||
try {
|
||||
// Get symbols that need updating
|
||||
const staleSymbols = await tracker.getStaleSymbols('filings_update', {
|
||||
const staleSymbols = await this.operationRegistry.getStaleSymbols('qm', 'filings_update', {
|
||||
minHoursSinceRun: forceUpdate ? 0 : 24, // Daily for filings
|
||||
limit
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue