bulltrackers-module 1.0.358 → 1.0.359
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.
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Main entry point for the Task Engine Cloud Function.
|
|
3
|
-
* Routes incoming Pub/Sub messages to the appropriate helper functions.
|
|
4
3
|
*/
|
|
5
4
|
const { handleDiscover } = require('./helpers/discover_helpers');
|
|
6
5
|
const { handleVerify } = require('./helpers/verify_helpers');
|
|
7
|
-
const { handleUpdate } = require('./helpers/update_helpers');
|
|
6
|
+
const { handleUpdate } = require('./helpers/update_helpers');
|
|
8
7
|
const { handlePopularInvestorUpdate, handleOnDemandUserUpdate } = require('./helpers/popular_investor_helpers');
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* @param {object} context - The event context.
|
|
14
|
-
* @param {object} config - The Task Engine configuration.
|
|
15
|
-
* @param {object} dependencies - Injected dependencies (db, logger, proxyManager, etc.).
|
|
16
|
-
*/
|
|
9
|
+
// IMPORT THE UTILS TO HANDLE BATCHES
|
|
10
|
+
const { executeTasks, prepareTaskBatches } = require('./utils/task_engine_utils');
|
|
11
|
+
|
|
17
12
|
async function handleRequest(message, context, config, dependencies) {
|
|
18
13
|
const { logger } = dependencies;
|
|
19
14
|
|
|
@@ -27,12 +22,27 @@ async function handleRequest(message, context, config, dependencies) {
|
|
|
27
22
|
return;
|
|
28
23
|
}
|
|
29
24
|
|
|
25
|
+
// --- FIX START: Handle Batch vs Single ---
|
|
26
|
+
|
|
27
|
+
// CASE A: Payload is a Batch (from Dispatcher)
|
|
28
|
+
if (payload.tasks && Array.isArray(payload.tasks)) {
|
|
29
|
+
logger.log('INFO', `[TaskEngine] Received BATCH of ${payload.tasks.length} tasks.`);
|
|
30
|
+
const taskId = context.eventId || 'batch-' + Date.now();
|
|
31
|
+
|
|
32
|
+
// Use existing utils to execute the batch
|
|
33
|
+
const { tasksToRun, otherTasks } = await prepareTaskBatches(payload.tasks, null, logger);
|
|
34
|
+
await executeTasks(tasksToRun, otherTasks, dependencies, config, taskId);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// CASE B: Payload is a Single Task (from Cron/On-Demand)
|
|
30
39
|
const { type, data } = payload;
|
|
31
40
|
|
|
32
41
|
if (!type) {
|
|
33
42
|
logger.log('WARN', '[TaskEngine] Received message with no type.', payload);
|
|
34
43
|
return;
|
|
35
44
|
}
|
|
45
|
+
// --- FIX END ---
|
|
36
46
|
|
|
37
47
|
logger.log('INFO', `[TaskEngine] Processing Task: ${type}`, { dataSummary: JSON.stringify(data).substring(0, 100) });
|
|
38
48
|
|
|
@@ -40,23 +50,18 @@ async function handleRequest(message, context, config, dependencies) {
|
|
|
40
50
|
try {
|
|
41
51
|
switch (type) {
|
|
42
52
|
case 'DISCOVER':
|
|
43
|
-
await handleDiscover(data,
|
|
53
|
+
await handleDiscover(data, 'single-discover', dependencies, config); // Added taskId arg
|
|
44
54
|
break;
|
|
45
55
|
case 'VERIFY':
|
|
46
|
-
await handleVerify(data,
|
|
56
|
+
await handleVerify(data, 'single-verify', dependencies, config); // Added taskId arg
|
|
47
57
|
break;
|
|
48
58
|
case 'UPDATE':
|
|
49
|
-
|
|
50
|
-
await handleUpdate(data, config, dependencies);
|
|
59
|
+
await handleUpdate(data, 'single-update', dependencies, config); // Added taskId arg
|
|
51
60
|
break;
|
|
52
61
|
case 'POPULAR_INVESTOR_UPDATE':
|
|
53
|
-
// New logic for Popular Investors (daily cron, high fidelity)
|
|
54
|
-
// data should contain { cid, username }
|
|
55
62
|
await handlePopularInvestorUpdate(data, config, dependencies);
|
|
56
63
|
break;
|
|
57
64
|
case 'ON_DEMAND_USER_UPDATE':
|
|
58
|
-
// New logic for Signed-In Users (immediate trigger, cost optimized)
|
|
59
|
-
// data should contain { cid, username }
|
|
60
65
|
await handleOnDemandUserUpdate(data, config, dependencies);
|
|
61
66
|
break;
|
|
62
67
|
default:
|
|
@@ -64,8 +69,6 @@ async function handleRequest(message, context, config, dependencies) {
|
|
|
64
69
|
}
|
|
65
70
|
} catch (err) {
|
|
66
71
|
logger.log('ERROR', `[TaskEngine] Error processing task ${type}`, err);
|
|
67
|
-
// We might want to throw here to trigger Pub/Sub retry, depending on the error nature
|
|
68
|
-
// For now, logging error is sufficient as the sub-handlers perform their own try/catch blocks
|
|
69
72
|
}
|
|
70
73
|
}
|
|
71
74
|
|