You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`Failed to return jobs from local queue to database queue (attempt ${attempts}/${MAX_ATTEMPTS})`,
444
+
{error: e, attempts,maxAttempts: MAX_ATTEMPTS},
445
+
);
446
+
447
+
// NOTE: the mode now may not be the mode that we were in when
448
+
// returnJobs was called. An error happened... we need to deal with
449
+
// this error gracefully.
450
+
switch(this.mode){
451
+
case"RELEASED": {
452
+
thrownewError(
453
+
`Error occurred whilst returning jobs from local queue to database queue: ${initialError.message}`,
454
+
);
455
+
}
456
+
457
+
// NOTE: considered doing `this.receivedJobs(jobsToReturn)`; but I
458
+
// simply trying to release them again seems safer and more correct.
459
+
default: {
460
+
if(attempts<MAX_ATTEMPTS){
461
+
/** Minimum delay between attempts (milliseconds); can actually be half this due to jitter */
462
+
constminDelay=200;
463
+
/** Maximum delay between attempts (milliseconds) - can actually be 1.5x this due to jitter */
464
+
constmaxDelay=30_000;// Maximum delay in milliseconds
465
+
/** `multiplier ^ attempts` */
466
+
constmultiplier=1.5;
467
+
/** Prevent the thundering herd problem by offsetting randomly */
468
+
constjitter=Math.random();
469
+
constdelay=
470
+
Math.min(
471
+
minDelay*Math.pow(multiplier,attempts-1),
472
+
maxDelay,
473
+
)*
474
+
(0.5+jitter);
475
+
476
+
// Be sure to increment attempts to avoid infinite loop!
477
+
++attempts;
478
+
returnsleep(delay).then(()=>
479
+
returnJobs(
480
+
this.compiledSharedOptions,
481
+
this.withPgClient,
482
+
this.workerPool.id,
483
+
jobsToReturn,
484
+
).then(noop,onError),
485
+
);
486
+
}else{
487
+
// TODO: is this the correct way to handle this? Are we allowed to
488
+
// trigger shut down internally?
489
+
this.release();
490
+
// Now we're in release mode, throwing the error will be tracked
491
+
// automatically by `this.background()`
492
+
thrownewError(
493
+
`Error occurred whilst returning jobs from local queue to database queue; aborting after ${attempts} attempts. Initial error: ${initialError.message}`,
494
+
);
495
+
}
496
+
}
497
+
}
498
+
};
499
+
500
+
// NOTE: the `this.background` call covers all of the re-attempts via
501
+
// `onError` above, since `onError` returns the next promise each time.
425
502
this.background(
426
503
returnJobs(
427
504
this.compiledSharedOptions,
428
505
this.withPgClient,
429
506
this.workerPool.id,
430
507
jobsToReturn,
431
508
).then(
432
-
()=>{},
433
-
(e)=>{
434
-
if(this.mode==="RELEASED"){
435
-
thrownewError(
436
-
`Error occurred whilst returning jobs from local queue to database queue: ${
437
-
coerceError(e).message
438
-
}`,
439
-
);
440
-
}else{
441
-
// Return the jobs to the queue; MUST NOT HAPPEN IN RELEASED MODE.
442
-
this.receivedJobs(jobsToReturn);
443
-
this.compiledSharedOptions.logger.error(
444
-
`Failed to return jobs from local queue to database queue`,
0 commit comments