bulltrackers-module 1.0.500 → 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.
|
@@ -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
|
|