JobQueue: Don't start job if we're shutting down
This commit is contained in:
parent
fe10d5f249
commit
556dbe3114
1 changed files with 11 additions and 1 deletions
|
@ -252,6 +252,14 @@ export abstract class JobQueue<T> {
|
|||
log.info(
|
||||
`${this.logPrefix} running job ${storedJob.id}, attempt ${attempt} of ${this.maxAttempts}`
|
||||
);
|
||||
|
||||
if (this.isShuttingDown) {
|
||||
log.warn(
|
||||
`${this.logPrefix} returning early for job ${storedJob.id}; shutting down`
|
||||
);
|
||||
return { success: false, err: new Error('Shutting down') };
|
||||
}
|
||||
|
||||
try {
|
||||
// We want an `await` in the loop, as we don't want a single job running more
|
||||
// than once at a time. Ideally, the job will succeed on the first attempt.
|
||||
|
@ -277,7 +285,9 @@ export abstract class JobQueue<T> {
|
|||
return undefined;
|
||||
});
|
||||
|
||||
await this.store.delete(storedJob.id);
|
||||
if (result?.success || !this.isShuttingDown) {
|
||||
await this.store.delete(storedJob.id);
|
||||
}
|
||||
|
||||
assertDev(
|
||||
result,
|
||||
|
|
Loading…
Add table
Reference in a new issue