|
| 1 | +import * as assert from "assert"; |
1 | 2 | import { randomBytes } from "crypto";
|
2 | 3 | import { EventEmitter } from "events";
|
3 | 4 | import { Notification, Pool, PoolClient } from "pg";
|
@@ -594,34 +595,34 @@ export function _runTaskList(
|
594 | 595 |
|
595 | 596 | function deactivate() {
|
596 | 597 | if (!deactivatePromise) {
|
| 598 | + assert.equal(workerPool._active, true); |
| 599 | + workerPool._active = false; |
| 600 | + |
597 | 601 | deactivatePromise = (async () => {
|
598 |
| - if (workerPool._active) { |
599 |
| - workerPool._active = false; |
600 |
| - const errors: Error[] = []; |
601 |
| - try { |
602 |
| - await localQueue?.release(); |
603 |
| - } catch (rawE) { |
604 |
| - const e = coerceError(rawE); |
605 |
| - errors.push(e); |
606 |
| - // Log but continue regardless |
607 |
| - logger.error(`Releasing local queue failed: ${e}`, { error: rawE }); |
608 |
| - } |
609 |
| - try { |
610 |
| - // Note: this runs regardless of success of the above |
611 |
| - await onDeactivate?.(); |
612 |
| - } catch (rawE) { |
613 |
| - const e = coerceError(rawE); |
614 |
| - errors.push(e); |
615 |
| - // Log but continue regardless |
616 |
| - logger.error(`onDeactivate raised an error: ${e}`, { error: rawE }); |
617 |
| - } |
| 602 | + const errors: Error[] = []; |
| 603 | + try { |
| 604 | + await localQueue?.release(); |
| 605 | + } catch (rawE) { |
| 606 | + const e = coerceError(rawE); |
| 607 | + errors.push(e); |
| 608 | + // Log but continue regardless |
| 609 | + logger.error(`Releasing local queue failed: ${e}`, { error: rawE }); |
| 610 | + } |
| 611 | + try { |
| 612 | + // Note: this runs regardless of success of the above |
| 613 | + await onDeactivate?.(); |
| 614 | + } catch (rawE) { |
| 615 | + const e = coerceError(rawE); |
| 616 | + errors.push(e); |
| 617 | + // Log but continue regardless |
| 618 | + logger.error(`onDeactivate raised an error: ${e}`, { error: rawE }); |
| 619 | + } |
618 | 620 |
|
619 |
| - if (errors.length > 0) { |
620 |
| - throw new AggregateError( |
621 |
| - errors, |
622 |
| - "Errors occurred whilst deactivating queue", |
623 |
| - ); |
624 |
| - } |
| 621 | + if (errors.length > 0) { |
| 622 | + throw new AggregateError( |
| 623 | + errors, |
| 624 | + "Errors occurred whilst deactivating queue", |
| 625 | + ); |
625 | 626 | }
|
626 | 627 | })();
|
627 | 628 | }
|
@@ -1087,8 +1088,16 @@ export function _runTaskList(
|
1087 | 1088 | )
|
1088 | 1089 | : null;
|
1089 | 1090 | const getJob: GetJobFunction = localQueue
|
1090 |
| - ? localQueue.getJob // Already bound |
| 1091 | + ? async (workerId, flagsToSkip) => { |
| 1092 | + if (!workerPool._active) { |
| 1093 | + return undefined; |
| 1094 | + } |
| 1095 | + return localQueue.getJob(workerId, flagsToSkip); |
| 1096 | + } |
1091 | 1097 | : async (_workerId, flagsToSkip) => {
|
| 1098 | + if (!workerPool._active) { |
| 1099 | + return undefined; |
| 1100 | + } |
1092 | 1101 | const jobs = await baseGetJob(
|
1093 | 1102 | compiledSharedOptions,
|
1094 | 1103 | withPgClient,
|
|
0 commit comments