bulltrackers-module 1.0.665 → 1.0.666
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.
|
@@ -130,10 +130,14 @@ async function getStableDateSession(config, dependencies, pass, dateLimitStr, fo
|
|
|
130
130
|
// HANDLERS
|
|
131
131
|
// =============================================================================
|
|
132
132
|
|
|
133
|
-
// 2. NEW SNAPSHOT HANDLER
|
|
133
|
+
// 2. NEW SNAPSHOT HANDLER (Asynchronous with Callback)
|
|
134
134
|
async function handleSnapshot(config, dependencies, reqBody) {
|
|
135
135
|
const { logger } = dependencies;
|
|
136
136
|
const targetDate = reqBody.date; // Optional: if provided, only process up to this date
|
|
137
|
+
const callbackUrl = reqBody.callback_url; // Callback URL from workflow
|
|
138
|
+
|
|
139
|
+
// Use native fetch if available (Node 18+), otherwise fall back to node-fetch
|
|
140
|
+
const directFetch = typeof fetch !== 'undefined' ? fetch : require('node-fetch');
|
|
137
141
|
|
|
138
142
|
try {
|
|
139
143
|
// Get earliest available root data date
|
|
@@ -156,7 +160,19 @@ async function handleSnapshot(config, dependencies, reqBody) {
|
|
|
156
160
|
|
|
157
161
|
if (dateStrings.length === 0) {
|
|
158
162
|
logger.log('WARN', '[Dispatcher] No dates to process for snapshot');
|
|
159
|
-
|
|
163
|
+
const finalResult = { status: 'OK', processed: 0, skipped: 0 };
|
|
164
|
+
|
|
165
|
+
// Send callback if provided
|
|
166
|
+
if (callbackUrl) {
|
|
167
|
+
logger.log('INFO', '[Dispatcher] 📞 Calling back Workflow...');
|
|
168
|
+
await directFetch(callbackUrl, {
|
|
169
|
+
method: 'POST',
|
|
170
|
+
headers: { 'Content-Type': 'application/json' },
|
|
171
|
+
body: JSON.stringify(finalResult)
|
|
172
|
+
}).catch(err => logger.log('ERROR', `[Dispatcher] Callback failed: ${err.message}`));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return finalResult;
|
|
160
176
|
}
|
|
161
177
|
|
|
162
178
|
logger.log('INFO', `[Dispatcher] 📸 Processing snapshots for ${dateStrings.length} dates from ${dateStrings[0]} to ${dateStrings[dateStrings.length - 1]}`);
|
|
@@ -189,7 +205,7 @@ async function handleSnapshot(config, dependencies, reqBody) {
|
|
|
189
205
|
|
|
190
206
|
logger.log('INFO', `[Dispatcher] 📸 Snapshot batch complete: ${successful} processed, ${skipped} skipped, ${failed} failed out of ${results.length} total`);
|
|
191
207
|
|
|
192
|
-
|
|
208
|
+
const finalResult = {
|
|
193
209
|
status: failed === 0 ? 'OK' : 'PARTIAL',
|
|
194
210
|
processed: successful,
|
|
195
211
|
skipped: skipped,
|
|
@@ -197,10 +213,33 @@ async function handleSnapshot(config, dependencies, reqBody) {
|
|
|
197
213
|
total: results.length,
|
|
198
214
|
results: results
|
|
199
215
|
};
|
|
216
|
+
|
|
217
|
+
// Send callback to workflow if provided
|
|
218
|
+
if (callbackUrl) {
|
|
219
|
+
logger.log('INFO', '[Dispatcher] 📞 Calling back Workflow...');
|
|
220
|
+
await directFetch(callbackUrl, {
|
|
221
|
+
method: 'POST',
|
|
222
|
+
headers: { 'Content-Type': 'application/json' },
|
|
223
|
+
body: JSON.stringify(finalResult)
|
|
224
|
+
}).catch(err => logger.log('ERROR', `[Dispatcher] Callback failed: ${err.message}`));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return finalResult;
|
|
200
228
|
} catch (e) {
|
|
201
229
|
logger.log('ERROR', `[Dispatcher] Snapshot failed: ${e.message}`);
|
|
202
|
-
|
|
203
|
-
|
|
230
|
+
const errorResult = { status: 'ERROR', error: e.message };
|
|
231
|
+
|
|
232
|
+
// Notify workflow of failure too, otherwise it hangs!
|
|
233
|
+
if (callbackUrl) {
|
|
234
|
+
logger.log('INFO', '[Dispatcher] 📞 Calling back Workflow with error...');
|
|
235
|
+
await directFetch(callbackUrl, {
|
|
236
|
+
method: 'POST',
|
|
237
|
+
headers: { 'Content-Type': 'application/json' },
|
|
238
|
+
body: JSON.stringify(errorResult)
|
|
239
|
+
}).catch(err => logger.log('ERROR', `[Dispatcher] Error callback failed: ${err.message}`));
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return errorResult;
|
|
204
243
|
}
|
|
205
244
|
}
|
|
206
245
|
|