JobQueue: Don't start job if we're shutting down

This commit is contained in:
Scott Nonnenberg 2023-03-16 13:17:35 -07:00 committed by GitHub
parent fe10d5f249
commit 556dbe3114
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -252,6 +252,14 @@ export abstract class JobQueue<T> {
log.info( log.info(
`${this.logPrefix} running job ${storedJob.id}, attempt ${attempt} of ${this.maxAttempts}` `${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 { try {
// We want an `await` in the loop, as we don't want a single job running more // 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. // 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; return undefined;
}); });
await this.store.delete(storedJob.id); if (result?.success || !this.isShuttingDown) {
await this.store.delete(storedJob.id);
}
assertDev( assertDev(
result, result,