wingbot 3.76.14 → 3.76.15
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.
- package/package.json +1 -1
- package/src/BuildRouter.js +65 -3
package/package.json
CHANGED
package/src/BuildRouter.js
CHANGED
|
@@ -206,6 +206,19 @@ const DUMMY_ROUTE = { id: 0, path: null, resolvers: [] };
|
|
|
206
206
|
* @prop {string|number} [resolverId] - only for text messages with random characters
|
|
207
207
|
*/
|
|
208
208
|
|
|
209
|
+
/**
|
|
210
|
+
* @typedef {object} Logger
|
|
211
|
+
* @prop {Function} log
|
|
212
|
+
* @prop {Function} error
|
|
213
|
+
*/
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* @typedef {object} RunningReq
|
|
217
|
+
* @prop {unknown[]} args
|
|
218
|
+
* @prop {Promise} promise
|
|
219
|
+
* @prop {number} started
|
|
220
|
+
*/
|
|
221
|
+
|
|
209
222
|
/**
|
|
210
223
|
* @template {BaseConfiguration} [C=object]
|
|
211
224
|
* @typedef {BotContextExtention & BuildRouterContext<C>} BotContext
|
|
@@ -300,10 +313,14 @@ class BuildRouter extends Router {
|
|
|
300
313
|
? context.then((c) => c.configStorage)
|
|
301
314
|
: context.configStorage;
|
|
302
315
|
|
|
316
|
+
/** @type {RunningReq[]} */
|
|
303
317
|
this._runningReqs = [];
|
|
304
318
|
|
|
305
319
|
this._configTs = 0;
|
|
306
320
|
|
|
321
|
+
/** @type {number} */
|
|
322
|
+
this.runningReqTimeout = 20000;
|
|
323
|
+
|
|
307
324
|
/**
|
|
308
325
|
* Timeout, when the router is not checking for new configuration
|
|
309
326
|
*
|
|
@@ -325,6 +342,20 @@ class BuildRouter extends Router {
|
|
|
325
342
|
}
|
|
326
343
|
}
|
|
327
344
|
|
|
345
|
+
/**
|
|
346
|
+
* @returns {Logger}
|
|
347
|
+
*/
|
|
348
|
+
get _logger () {
|
|
349
|
+
const logger = this._resolvedContext?.log
|
|
350
|
+
// @ts-ignore
|
|
351
|
+
|| this._resolvedContext?.configuration?.log;
|
|
352
|
+
|
|
353
|
+
if (typeof logger?.log === 'function') {
|
|
354
|
+
return logger;
|
|
355
|
+
}
|
|
356
|
+
return console;
|
|
357
|
+
}
|
|
358
|
+
|
|
328
359
|
get snapshot () {
|
|
329
360
|
return this._snapshot;
|
|
330
361
|
}
|
|
@@ -373,15 +404,35 @@ class BuildRouter extends Router {
|
|
|
373
404
|
await this.preload();
|
|
374
405
|
|
|
375
406
|
let runningRequest;
|
|
407
|
+
let timeout;
|
|
376
408
|
try {
|
|
377
409
|
const reducePromise = super.reduce(...args);
|
|
378
410
|
|
|
379
|
-
|
|
380
|
-
|
|
411
|
+
const timeoutPromise = new Promise((resolve) => {
|
|
412
|
+
timeout = setTimeout(() => {
|
|
413
|
+
timeout = null;
|
|
414
|
+
this._logger.error('BuildRouter EXPIRE', { args });
|
|
415
|
+
this._runningReqs = this._runningReqs
|
|
416
|
+
.filter((rr) => rr !== runningRequest);
|
|
417
|
+
resolve();
|
|
418
|
+
}, this.runningReqTimeout);
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
runningRequest = {
|
|
422
|
+
args,
|
|
423
|
+
promise: Promise.race([
|
|
424
|
+
reducePromise,
|
|
425
|
+
timeoutPromise
|
|
426
|
+
]).catch(() => { /* mute fails */ }),
|
|
427
|
+
started: Date.now()
|
|
428
|
+
};
|
|
381
429
|
this._runningReqs.push(runningRequest);
|
|
382
430
|
|
|
383
431
|
return await reducePromise;
|
|
384
432
|
} finally {
|
|
433
|
+
if (timeout) {
|
|
434
|
+
clearTimeout(timeout);
|
|
435
|
+
}
|
|
385
436
|
if (runningRequest) {
|
|
386
437
|
this._runningReqs = this._runningReqs
|
|
387
438
|
.filter((rr) => rr !== runningRequest);
|
|
@@ -471,7 +522,18 @@ class BuildRouter extends Router {
|
|
|
471
522
|
}
|
|
472
523
|
|
|
473
524
|
// wait for running request
|
|
474
|
-
|
|
525
|
+
const threshold = Date.now() - this.runningReqTimeout;
|
|
526
|
+
await Promise.all(
|
|
527
|
+
this._runningReqs
|
|
528
|
+
.filter((req) => {
|
|
529
|
+
if (req.started < threshold) {
|
|
530
|
+
this._logger.error('BuildRouter EXPIRE filter', req);
|
|
531
|
+
return false;
|
|
532
|
+
}
|
|
533
|
+
return true;
|
|
534
|
+
})
|
|
535
|
+
.map((req) => req.promise)
|
|
536
|
+
);
|
|
475
537
|
|
|
476
538
|
this.buildWithSnapshot(
|
|
477
539
|
snapshot.blocks,
|