bulltrackers-module 1.0.499 → 1.0.501
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -95,12 +95,23 @@ exports.runRootDataIndexer = async (config, dependencies) => {
|
|
|
95
95
|
logger.log('INFO', `[RootDataIndexer] Starting Root Data Availability Scan... Mode: ${scanMode}`, { targetDate });
|
|
96
96
|
|
|
97
97
|
// 1. Price Availability - Read from date tracking documents
|
|
98
|
-
// Find the latest
|
|
98
|
+
// Find the latest price tracking document and extract available dates
|
|
99
99
|
const priceAvailabilitySet = new Set();
|
|
100
100
|
|
|
101
|
+
// Get price tracking collection name from registry if available
|
|
102
|
+
let priceTrackingCollectionName = 'pricedatastoreddates';
|
|
103
|
+
if (dependencies.collectionRegistry && dependencies.collectionRegistry.getCollectionPath) {
|
|
104
|
+
try {
|
|
105
|
+
const trackingPath = dependencies.collectionRegistry.getCollectionPath('rootData', 'priceTracking', { fetchDate: '2025-01-01' });
|
|
106
|
+
priceTrackingCollectionName = trackingPath.split('/')[0];
|
|
107
|
+
} catch (e) {
|
|
108
|
+
logger.log('WARN', `[RootDataIndexer] Failed to get price tracking collection from registry, using default: ${e.message}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
101
112
|
try {
|
|
102
113
|
// Get the latest price date tracking document
|
|
103
|
-
const dateTrackingRef = db.collection(
|
|
114
|
+
const dateTrackingRef = db.collection(priceTrackingCollectionName)
|
|
104
115
|
.orderBy('fetchDate', 'desc')
|
|
105
116
|
.limit(1);
|
|
106
117
|
|
|
@@ -109,6 +120,7 @@ exports.runRootDataIndexer = async (config, dependencies) => {
|
|
|
109
120
|
if (!dateTrackingSnapshot.empty) {
|
|
110
121
|
const latestTrackingDoc = dateTrackingSnapshot.docs[0].data();
|
|
111
122
|
const datesAvailable = latestTrackingDoc.datesAvailable || [];
|
|
123
|
+
const fetchDate = latestTrackingDoc.fetchDate;
|
|
112
124
|
|
|
113
125
|
// Add all dates from the tracking document
|
|
114
126
|
datesAvailable.forEach(dateKey => {
|
|
@@ -117,7 +129,22 @@ exports.runRootDataIndexer = async (config, dependencies) => {
|
|
|
117
129
|
}
|
|
118
130
|
});
|
|
119
131
|
|
|
120
|
-
|
|
132
|
+
// IMPORTANT: If the tracking document was written for today (fetchDate matches targetDate),
|
|
133
|
+
// we should consider prices available for that date even if the API didn't return that exact date.
|
|
134
|
+
// This is because the price fetcher ran for that date and stored prices (even if they're historical).
|
|
135
|
+
if (targetDate && fetchDate === targetDate) {
|
|
136
|
+
priceAvailabilitySet.add(targetDate);
|
|
137
|
+
logger.log('INFO', `[RootDataIndexer] Added fetchDate (${fetchDate}) to price availability set for target date check`);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
logger.log('INFO', `[RootDataIndexer] Loaded ${priceAvailabilitySet.size} price dates from tracking document (fetchDate: ${fetchDate})`);
|
|
141
|
+
|
|
142
|
+
// Debug: Log a sample of dates and check if target date is present
|
|
143
|
+
if (targetDate) {
|
|
144
|
+
const sampleDates = Array.from(priceAvailabilitySet).slice(0, 5);
|
|
145
|
+
const hasTargetDate = priceAvailabilitySet.has(targetDate);
|
|
146
|
+
logger.log('INFO', `[RootDataIndexer] Price availability check for ${targetDate}: ${hasTargetDate ? 'FOUND' : 'NOT FOUND'}. Sample dates: ${sampleDates.join(', ')}`);
|
|
147
|
+
}
|
|
121
148
|
} else {
|
|
122
149
|
logger.log('WARN', '[RootDataIndexer] No price date tracking documents found. Falling back to empty set.');
|
|
123
150
|
}
|
|
@@ -395,17 +422,13 @@ exports.runRootDataIndexer = async (config, dependencies) => {
|
|
|
395
422
|
availability.hasSocial = foundPISocial || foundSignedInSocial || genericSocialExists;
|
|
396
423
|
|
|
397
424
|
// Price Check
|
|
398
|
-
if
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
// NOTE: The Global Scan at 01:00 UTC will strictly verify prices.
|
|
406
|
-
availability.hasPrices = priceAvailabilitySet.has(dateStr);
|
|
407
|
-
} else {
|
|
408
|
-
availability.hasPrices = priceAvailabilitySet.has(dateStr);
|
|
425
|
+
// Check if the target date exists in the price availability set
|
|
426
|
+
// The set is populated from the price tracking document's datesAvailable array
|
|
427
|
+
const hasPriceForDate = priceAvailabilitySet.has(dateStr);
|
|
428
|
+
availability.hasPrices = hasPriceForDate;
|
|
429
|
+
|
|
430
|
+
if (targetDate && !hasPriceForDate) {
|
|
431
|
+
logger.log('WARN', `[RootDataIndexer/${dateStr}] Price data not found in tracking document. Set size: ${priceAvailabilitySet.size}, Date checked: ${dateStr}`);
|
|
409
432
|
}
|
|
410
433
|
|
|
411
434
|
await db.collection(availabilityCollection).doc(dateStr).set(availability);
|
|
@@ -297,32 +297,59 @@ async function executeTasks(tasksToRun, otherTasks, dependencies, config, taskId
|
|
|
297
297
|
|
|
298
298
|
// 6. For batch processing (global cron route), check if we need to run root data indexer
|
|
299
299
|
// This handles the edge case where no on-demand requests were made
|
|
300
|
+
// NOTE: We add a small delay to ensure all Firestore counter updates have propagated
|
|
300
301
|
if (targetDate && (batchCounterRef || socialCounterRef)) {
|
|
301
|
-
//
|
|
302
|
-
|
|
302
|
+
// Wait a moment for Firestore writes to propagate
|
|
303
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
304
|
+
|
|
305
|
+
// Check both counters to see if all tasks are complete (with retry logic)
|
|
306
|
+
let allComplete = false;
|
|
303
307
|
let allTasks = [...tasksToRun, ...otherTasks, ...socialTasks];
|
|
308
|
+
const maxRetries = 3;
|
|
309
|
+
let retries = 0;
|
|
304
310
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
311
|
+
while (retries < maxRetries && !allComplete) {
|
|
312
|
+
allComplete = true;
|
|
313
|
+
|
|
314
|
+
if (batchCounterRef) {
|
|
315
|
+
const batchCounterDoc = await batchCounterRef.get();
|
|
316
|
+
if (batchCounterDoc.exists) {
|
|
317
|
+
const batchData = batchCounterDoc.data();
|
|
318
|
+
logger.log('INFO', `[TaskEngine/${taskId}] Batch counter check (attempt ${retries + 1}): remainingTasks=${batchData.remainingTasks}, totalTasks=${batchData.totalTasks}, failedTasks=${batchData.failedTasks || 0}`);
|
|
319
|
+
if (batchData.remainingTasks > 0) {
|
|
320
|
+
allComplete = false;
|
|
321
|
+
}
|
|
322
|
+
} else {
|
|
323
|
+
logger.log('WARN', `[TaskEngine/${taskId}] Batch counter document does not exist`);
|
|
310
324
|
allComplete = false;
|
|
311
325
|
}
|
|
312
326
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
327
|
+
|
|
328
|
+
if (socialCounterRef) {
|
|
329
|
+
const socialCounterDoc = await socialCounterRef.get();
|
|
330
|
+
if (socialCounterDoc.exists) {
|
|
331
|
+
const socialData = socialCounterDoc.data();
|
|
332
|
+
logger.log('INFO', `[TaskEngine/${taskId}] Social counter check (attempt ${retries + 1}): remainingTasks=${socialData.remainingTasks}, totalTasks=${socialData.totalTasks}, failedTasks=${socialData.failedTasks || 0}`);
|
|
333
|
+
if (socialData.remainingTasks > 0) {
|
|
334
|
+
allComplete = false;
|
|
335
|
+
}
|
|
336
|
+
} else {
|
|
337
|
+
logger.log('WARN', `[TaskEngine/${taskId}] Social counter document does not exist`);
|
|
320
338
|
allComplete = false;
|
|
321
339
|
}
|
|
322
340
|
}
|
|
341
|
+
|
|
342
|
+
if (!allComplete && retries < maxRetries - 1) {
|
|
343
|
+
// Wait before retrying (exponential backoff)
|
|
344
|
+
await new Promise(resolve => setTimeout(resolve, 1000 * (retries + 1)));
|
|
345
|
+
retries++;
|
|
346
|
+
} else {
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
323
349
|
}
|
|
324
350
|
|
|
325
351
|
if (allComplete) {
|
|
352
|
+
logger.log('INFO', `[TaskEngine/${taskId}] All tasks complete. Triggering root data indexer for ${targetDate}...`);
|
|
326
353
|
// All tasks complete - conditionally trigger root data indexer
|
|
327
354
|
const dataTypesRun = determineDataTypesRun(allTasks);
|
|
328
355
|
|
|
@@ -338,6 +365,8 @@ async function executeTasks(tasksToRun, otherTasks, dependencies, config, taskId
|
|
|
338
365
|
counterRef: primaryCounterRef,
|
|
339
366
|
dataTypesRun
|
|
340
367
|
});
|
|
368
|
+
} else {
|
|
369
|
+
logger.log('WARN', `[TaskEngine/${taskId}] Not all tasks complete after ${maxRetries} checks. Remaining tasks may still be processing. Root data indexer will be triggered by the next task to complete or by the global cron.`);
|
|
341
370
|
}
|
|
342
371
|
}
|
|
343
372
|
|