finished intra-day crawl

This commit is contained in:
Boki 2025-07-02 18:26:30 -04:00
parent c9a679d9a5
commit 11c24b2280
12 changed files with 437 additions and 896 deletions

View file

@ -317,7 +317,8 @@ export class OperationTracker {
const {
limit = 1000,
excludeSymbols = [],
activeOnly = true
activeOnly = true,
symbolFilter
} = options;
this.provider.validateOperation(operationName);
@ -345,6 +346,11 @@ export class OperationTracker {
filter[symbolField] = { $nin: excludeSymbols };
}
// Add symbol filter if provided
if (symbolFilter?.symbol) {
filter.symbol = symbolFilter.symbol;
}
const symbols = await this.mongodb.find(collectionName, filter, {
limit,
projection: { [symbolField]: 1 },
@ -431,10 +437,11 @@ export class OperationTracker {
limit?: number;
targetOldestDate?: Date;
includeNewDataGaps?: boolean;
symbolFilter?: { symbol?: string };
} = {}
): Promise<Array<SymbolWithOperations & { gaps?: { forward?: boolean; backward?: boolean } }>> {
const { collectionName, symbolField } = this.provider.getProviderConfig();
const { limit = 100, targetOldestDate, includeNewDataGaps = true } = options;
const { limit = 100, targetOldestDate, includeNewDataGaps = true, symbolFilter } = options;
this.provider.validateOperation(operationName);
@ -443,6 +450,11 @@ export class OperationTracker {
active: { $ne: false }
};
// Add symbol filter if provided
if (symbolFilter?.symbol) {
filter.symbol = symbolFilter.symbol;
}
// Get all symbols that either:
// 1. Have never been crawled
// 2. Are not finished
@ -468,7 +480,11 @@ export class OperationTracker {
limit,
projection: {
[symbolField]: 1,
[`operations.${operationName}`]: 1
[`operations.${operationName}`]: 1,
// Include common fields that might be needed
symbol: 1,
exchange: 1,
qmSearchCode: 1
},
sort: {
[`operations.${operationName}.lastRunAt`]: 1
@ -479,19 +495,11 @@ export class OperationTracker {
const opStatus = doc.operations?.[operationName];
const crawlState = opStatus?.crawlState;
// Determine gaps
// Determine gaps (only backward since we removed forward crawling)
const gaps: { forward?: boolean; backward?: boolean } = {};
if (crawlState) {
// Check for forward gap (new data)
if (crawlState.newestDateReached) {
const daysSinceNewest = Math.floor(
(Date.now() - new Date(crawlState.newestDateReached).getTime()) / (1000 * 60 * 60 * 24)
);
gaps.forward = daysSinceNewest > 1;
}
// Check for backward gap (historical data)
// Only check for backward gap (historical data)
if (!crawlState.finished) {
gaps.backward = true;
if (targetOldestDate && crawlState.oldestDateReached) {
@ -499,8 +507,7 @@ export class OperationTracker {
}
}
} else {
// Never crawled, has both gaps
gaps.forward = true;
// Never crawled, needs backward crawl
gaps.backward = true;
}
@ -508,8 +515,11 @@ export class OperationTracker {
symbol: doc[symbolField],
lastRecordDate: opStatus?.lastRecordDate,
operationStatus: opStatus,
gaps
};
gaps,
// Include other potentially useful fields
exchange: doc.exchange,
qmSearchCode: doc.qmSearchCode || doc[symbolField]
} as SymbolWithOperations & { gaps?: { forward?: boolean; backward?: boolean } };
});
}

View file

@ -114,6 +114,8 @@ export interface StaleSymbolOptions {
excludeSymbols?: string[];
/** Only include active symbols */
activeOnly?: boolean;
/** Filter for specific symbols */
symbolFilter?: { symbol?: string };
}
/**