bulltrackers-module 1.0.48 → 1.0.50
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.
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
* @fileoverview Main entry point for the Dispatcher function.
|
|
3
3
|
* REFACTORED: This file now contains the main pipe function 'handleRequest'.
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
// --- 1. REMOVE the circular require ---
|
|
7
|
+
// const { pipe } = require('../../index'); // <<< REMOVE THIS LINE
|
|
8
|
+
|
|
9
|
+
// --- 2. ADD direct require for the specific sub-pipe needed ---
|
|
10
|
+
const { dispatchTasksInBatches } = require('./helpers/dispatch_helpers');
|
|
11
|
+
|
|
6
12
|
|
|
7
13
|
/**
|
|
8
14
|
* Main pipe: pipe.dispatcher.handleRequest
|
|
@@ -32,8 +38,9 @@ async function handleRequest(message, context, config, dependencies) {
|
|
|
32
38
|
throw new Error("Dispatcher module received invalid configuration.");
|
|
33
39
|
}
|
|
34
40
|
|
|
35
|
-
//
|
|
36
|
-
|
|
41
|
+
// --- 3. Use the directly required function ---
|
|
42
|
+
// Call the sub-pipe -> becomes dispatchTasksInBatches
|
|
43
|
+
await dispatchTasksInBatches(tasks, dependencies, config); // <<< USE DIRECTLY
|
|
37
44
|
|
|
38
45
|
} catch (error) {
|
|
39
46
|
logger.log('ERROR', '[Module Dispatcher] FATAL error processing message', { errorMessage: error.message, errorStack: error.stack });
|
|
@@ -43,4 +50,4 @@ async function handleRequest(message, context, config, dependencies) {
|
|
|
43
50
|
|
|
44
51
|
module.exports = {
|
|
45
52
|
handleRequest,
|
|
46
|
-
};
|
|
53
|
+
};
|
|
@@ -4,7 +4,14 @@
|
|
|
4
4
|
* that are called by the Cloud Function entry points.
|
|
5
5
|
* They receive all dependencies.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
// --- 1. REMOVE the circular require ---
|
|
9
|
+
// const { pipe } = require('../../index'); // Get the pipe object // <<< REMOVE THIS LINE
|
|
10
|
+
|
|
11
|
+
// --- 2. ADD direct requires for the specific sub-pipes needed ---
|
|
12
|
+
const { checkDiscoveryNeed, getDiscoveryCandidates, dispatchDiscovery } = require('./helpers/discovery_helpers');
|
|
13
|
+
const { getUpdateTargets, dispatchUpdates } = require('./helpers/update_helpers');
|
|
14
|
+
|
|
8
15
|
|
|
9
16
|
/**
|
|
10
17
|
* Main pipe for running the complete discovery orchestration process.
|
|
@@ -16,13 +23,14 @@ const { pipe } = require('../../index'); // Get the pipe object
|
|
|
16
23
|
async function runDiscoveryOrchestrator(config, dependencies) {
|
|
17
24
|
const { logger, firestoreUtils } = dependencies;
|
|
18
25
|
logger.log('INFO', '🚀 Discovery Orchestrator triggered via module...');
|
|
19
|
-
|
|
26
|
+
|
|
20
27
|
// Call sub-pipe from core
|
|
21
28
|
await firestoreUtils.resetProxyLocks(dependencies, config);
|
|
22
29
|
|
|
23
30
|
// Call sub-pipe for 'normal'
|
|
31
|
+
// Pass the directly required sub-pipe functions implicitly via runDiscovery call context
|
|
24
32
|
await runDiscovery('normal', config.discoveryConfig.normal, config, dependencies);
|
|
25
|
-
|
|
33
|
+
|
|
26
34
|
// Call sub-pipe for 'speculator'
|
|
27
35
|
await runDiscovery('speculator', config.discoveryConfig.speculator, config, dependencies);
|
|
28
36
|
}
|
|
@@ -37,13 +45,13 @@ async function runDiscoveryOrchestrator(config, dependencies) {
|
|
|
37
45
|
async function runUpdateOrchestrator(config, dependencies) {
|
|
38
46
|
const { logger, firestoreUtils } = dependencies;
|
|
39
47
|
logger.log('INFO', '🚀 Update Orchestrator triggered via module...');
|
|
40
|
-
|
|
48
|
+
|
|
41
49
|
// Call sub-pipe from core
|
|
42
50
|
await firestoreUtils.resetProxyLocks(dependencies, config);
|
|
43
51
|
|
|
44
52
|
// Call sub-pipe for 'normal'
|
|
45
53
|
await runUpdates('normal', config.updateConfig, config, dependencies);
|
|
46
|
-
|
|
54
|
+
|
|
47
55
|
// Call sub-pipe for 'speculator'
|
|
48
56
|
await runUpdates('speculator', config.updateConfig, config, dependencies);
|
|
49
57
|
}
|
|
@@ -62,8 +70,9 @@ async function runDiscovery(userType, userTypeConfig, globalConfig, dependencies
|
|
|
62
70
|
const { logger } = dependencies;
|
|
63
71
|
logger.log('INFO', `[Module Orchestrator] Starting discovery for ${userType} users...`);
|
|
64
72
|
|
|
65
|
-
//
|
|
66
|
-
|
|
73
|
+
// --- 3. Use the directly required functions ---
|
|
74
|
+
// 1. pipe.orchestrator.checkDiscoveryNeed -> becomes checkDiscoveryNeed
|
|
75
|
+
const { needsDiscovery, blocksToFill } = await checkDiscoveryNeed(
|
|
67
76
|
userType,
|
|
68
77
|
userTypeConfig,
|
|
69
78
|
dependencies
|
|
@@ -74,16 +83,16 @@ async function runDiscovery(userType, userTypeConfig, globalConfig, dependencies
|
|
|
74
83
|
return;
|
|
75
84
|
}
|
|
76
85
|
|
|
77
|
-
// 2. pipe.orchestrator.getDiscoveryCandidates
|
|
78
|
-
const candidates = await
|
|
86
|
+
// 2. pipe.orchestrator.getDiscoveryCandidates -> becomes getDiscoveryCandidates
|
|
87
|
+
const candidates = await getDiscoveryCandidates(
|
|
79
88
|
userType,
|
|
80
89
|
blocksToFill,
|
|
81
90
|
userTypeConfig,
|
|
82
91
|
dependencies
|
|
83
92
|
);
|
|
84
93
|
|
|
85
|
-
// 3. pipe.orchestrator.dispatchDiscovery
|
|
86
|
-
await
|
|
94
|
+
// 3. pipe.orchestrator.dispatchDiscovery -> becomes dispatchDiscovery
|
|
95
|
+
await dispatchDiscovery(
|
|
87
96
|
userType,
|
|
88
97
|
candidates,
|
|
89
98
|
userTypeConfig,
|
|
@@ -114,16 +123,17 @@ async function runUpdates(userType, updateConfig, globalConfig, dependencies) {
|
|
|
114
123
|
gracePeriodThreshold: sevenDaysAgoUTC
|
|
115
124
|
};
|
|
116
125
|
|
|
117
|
-
//
|
|
118
|
-
|
|
126
|
+
// --- 4. Use the directly required functions ---
|
|
127
|
+
// 1. pipe.orchestrator.getUpdateTargets -> becomes getUpdateTargets
|
|
128
|
+
const targets = await getUpdateTargets(
|
|
119
129
|
userType,
|
|
120
130
|
thresholds,
|
|
121
131
|
updateConfig,
|
|
122
132
|
dependencies
|
|
123
133
|
);
|
|
124
134
|
|
|
125
|
-
// 2. pipe.orchestrator.dispatchUpdates
|
|
126
|
-
await
|
|
135
|
+
// 2. pipe.orchestrator.dispatchUpdates -> becomes dispatchUpdates
|
|
136
|
+
await dispatchUpdates(
|
|
127
137
|
targets,
|
|
128
138
|
userType,
|
|
129
139
|
updateConfig,
|
|
@@ -139,4 +149,4 @@ module.exports = {
|
|
|
139
149
|
// Exporting these internal helpers so the main index.js can map them
|
|
140
150
|
runDiscovery,
|
|
141
151
|
runUpdates
|
|
142
|
-
};
|
|
152
|
+
};
|
|
@@ -3,7 +3,14 @@
|
|
|
3
3
|
* REFACTORED: This file is now 'handler_creator.js' in name only.
|
|
4
4
|
* It exports the main 'handleRequest' pipe function.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
// --- 1. REMOVE the circular require ---
|
|
8
|
+
// const { pipe } = require('../../index'); // <<< REMOVE THIS LINE
|
|
9
|
+
|
|
10
|
+
// --- 2. ADD direct requires for the specific sub-pipes needed ---
|
|
11
|
+
const { handleDiscover } = require('./helpers/discover_helpers');
|
|
12
|
+
const { handleVerify } = require('./helpers/verify_helpers');
|
|
13
|
+
const { handleUpdate } = require('./helpers/update_helpers');
|
|
7
14
|
|
|
8
15
|
/**
|
|
9
16
|
* Main pipe: pipe.taskEngine.handleRequest
|
|
@@ -35,11 +42,12 @@ async function handleRequest(message, context, config, dependencies) {
|
|
|
35
42
|
try {
|
|
36
43
|
await new Promise(resolve => setTimeout(resolve, Math.random() * 500 + 250));
|
|
37
44
|
|
|
45
|
+
// --- 3. Use the directly required functions ---
|
|
38
46
|
// Route to the correct sub-pipe
|
|
39
47
|
const handlerFunction = {
|
|
40
|
-
discover:
|
|
41
|
-
verify:
|
|
42
|
-
update:
|
|
48
|
+
discover: handleDiscover, // <<< USE DIRECTLY
|
|
49
|
+
verify: handleVerify, // <<< USE DIRECTLY
|
|
50
|
+
update: handleUpdate // <<< USE DIRECTLY
|
|
43
51
|
}[task.type];
|
|
44
52
|
|
|
45
53
|
if (handlerFunction) {
|
|
@@ -51,7 +59,7 @@ async function handleRequest(message, context, config, dependencies) {
|
|
|
51
59
|
}
|
|
52
60
|
} catch (error) {
|
|
53
61
|
logger.log('ERROR', `[TaskEngine/${taskId}] Failed.`, { errorMessage: error.message, errorStack: error.stack });
|
|
54
|
-
|
|
62
|
+
|
|
55
63
|
// If a header was used, ensure its failure is recorded even on a crash
|
|
56
64
|
// This is a simplistic way; ideally, the sub-pipes manage this.
|
|
57
65
|
// Let's rely on sub-pipes' finally blocks.
|
|
@@ -69,4 +77,4 @@ async function handleRequest(message, context, config, dependencies) {
|
|
|
69
77
|
|
|
70
78
|
module.exports = {
|
|
71
79
|
handleRequest,
|
|
72
|
-
};
|
|
80
|
+
};
|