bulltrackers-module 1.0.666 → 1.0.667

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.
@@ -136,6 +136,8 @@ async function handleSnapshot(config, dependencies, reqBody) {
136
136
  const targetDate = reqBody.date; // Optional: if provided, only process up to this date
137
137
  const callbackUrl = reqBody.callback_url; // Callback URL from workflow
138
138
 
139
+ logger.log('INFO', `[Dispatcher] 📸 Snapshot request received. Date: ${targetDate || 'all'}, Callback URL: ${callbackUrl || 'NOT PROVIDED'}`);
140
+
139
141
  // Use native fetch if available (Node 18+), otherwise fall back to node-fetch
140
142
  const directFetch = typeof fetch !== 'undefined' ? fetch : require('node-fetch');
141
143
 
@@ -164,12 +166,32 @@ async function handleSnapshot(config, dependencies, reqBody) {
164
166
 
165
167
  // Send callback if provided
166
168
  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}`));
169
+ logger.log('INFO', `[Dispatcher] 📞 Calling back Workflow at: ${callbackUrl}`);
170
+ try {
171
+ // Add timeout to prevent hanging (30 seconds should be plenty for a callback)
172
+ const timeoutPromise = new Promise((_, reject) =>
173
+ setTimeout(() => reject(new Error('Callback timeout after 30s')), 30000)
174
+ );
175
+
176
+ const fetchPromise = directFetch(callbackUrl, {
177
+ method: 'POST',
178
+ headers: { 'Content-Type': 'application/json' },
179
+ body: JSON.stringify(finalResult)
180
+ });
181
+
182
+ const response = await Promise.race([fetchPromise, timeoutPromise]);
183
+
184
+ if (!response.ok) {
185
+ const errorText = await response.text().catch(() => 'Unable to read response');
186
+ logger.log('ERROR', `[Dispatcher] Callback returned non-OK status: ${response.status} ${response.statusText}. Response: ${errorText.substring(0, 200)}`);
187
+ } else {
188
+ logger.log('INFO', `[Dispatcher] ✅ Callback sent successfully (status: ${response.status})`);
189
+ }
190
+ } catch (err) {
191
+ logger.log('ERROR', `[Dispatcher] Callback failed: ${err.message}. Stack: ${err.stack?.substring(0, 300)}`);
192
+ }
193
+ } else {
194
+ logger.log('WARN', '[Dispatcher] No callback URL provided, workflow will not be notified');
173
195
  }
174
196
 
175
197
  return finalResult;
@@ -216,12 +238,32 @@ async function handleSnapshot(config, dependencies, reqBody) {
216
238
 
217
239
  // Send callback to workflow if provided
218
240
  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}`));
241
+ logger.log('INFO', `[Dispatcher] 📞 Calling back Workflow at: ${callbackUrl}`);
242
+ try {
243
+ // Add timeout to prevent hanging (30 seconds should be plenty for a callback)
244
+ const timeoutPromise = new Promise((_, reject) =>
245
+ setTimeout(() => reject(new Error('Callback timeout after 30s')), 30000)
246
+ );
247
+
248
+ const fetchPromise = directFetch(callbackUrl, {
249
+ method: 'POST',
250
+ headers: { 'Content-Type': 'application/json' },
251
+ body: JSON.stringify(finalResult)
252
+ });
253
+
254
+ const response = await Promise.race([fetchPromise, timeoutPromise]);
255
+
256
+ if (!response.ok) {
257
+ const errorText = await response.text().catch(() => 'Unable to read response');
258
+ logger.log('ERROR', `[Dispatcher] Callback returned non-OK status: ${response.status} ${response.statusText}. Response: ${errorText.substring(0, 200)}`);
259
+ } else {
260
+ logger.log('INFO', `[Dispatcher] ✅ Callback sent successfully (status: ${response.status})`);
261
+ }
262
+ } catch (err) {
263
+ logger.log('ERROR', `[Dispatcher] Callback failed: ${err.message}. Stack: ${err.stack?.substring(0, 300)}`);
264
+ }
265
+ } else {
266
+ logger.log('WARN', '[Dispatcher] No callback URL provided, workflow will not be notified');
225
267
  }
226
268
 
227
269
  return finalResult;
@@ -231,12 +273,32 @@ async function handleSnapshot(config, dependencies, reqBody) {
231
273
 
232
274
  // Notify workflow of failure too, otherwise it hangs!
233
275
  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}`));
276
+ logger.log('INFO', `[Dispatcher] 📞 Calling back Workflow with error at: ${callbackUrl}`);
277
+ try {
278
+ // Add timeout to prevent hanging (30 seconds should be plenty for a callback)
279
+ const timeoutPromise = new Promise((_, reject) =>
280
+ setTimeout(() => reject(new Error('Callback timeout after 30s')), 30000)
281
+ );
282
+
283
+ const fetchPromise = directFetch(callbackUrl, {
284
+ method: 'POST',
285
+ headers: { 'Content-Type': 'application/json' },
286
+ body: JSON.stringify(errorResult)
287
+ });
288
+
289
+ const response = await Promise.race([fetchPromise, timeoutPromise]);
290
+
291
+ if (!response.ok) {
292
+ const errorText = await response.text().catch(() => 'Unable to read response');
293
+ logger.log('ERROR', `[Dispatcher] Error callback returned non-OK status: ${response.status} ${response.statusText}. Response: ${errorText.substring(0, 200)}`);
294
+ } else {
295
+ logger.log('INFO', `[Dispatcher] ✅ Error callback sent successfully (status: ${response.status})`);
296
+ }
297
+ } catch (err) {
298
+ logger.log('ERROR', `[Dispatcher] Error callback failed: ${err.message}. Stack: ${err.stack?.substring(0, 300)}`);
299
+ }
300
+ } else {
301
+ logger.log('WARN', '[Dispatcher] No callback URL provided, workflow will not be notified of error');
240
302
  }
241
303
 
242
304
  return errorResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.666",
3
+ "version": "1.0.667",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [