Skip to content

Commit

Permalink
refactor(scripts): add protected moveStalledJobsToWaitArgs method (#2538
Browse files Browse the repository at this point in the history
)
  • Loading branch information
roggervalf committed Apr 23, 2024
1 parent b91dd72 commit 0fb9b85
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/classes/scripts.ts
Expand Up @@ -1092,18 +1092,7 @@ export class Scripts {
}
}

/**
* Looks for unlocked jobs in the active queue.
*
* The job was being worked on, but the worker process died and it failed to renew the lock.
* We call these jobs 'stalled'. This is the most common case. We resolve these by moving them
* back to wait to be re-processed. To prevent jobs from cycling endlessly between active and wait,
* (e.g. if the job handler keeps crashing),
* we limit the number stalled job recoveries to settings.maxStalledCount.
*/
async moveStalledJobsToWait(): Promise<[string[], string[]]> {
const client = await this.queue.client;

protected moveStalledJobsToWaitArgs(): (string | number)[] {
const opts = this.queue.opts as WorkerOptions;
const keys: (string | number)[] = [
this.queue.keys.stalled,
Expand All @@ -1122,7 +1111,25 @@ export class Scripts {
Date.now(),
opts.stalledInterval,
];
return (<any>client).moveStalledJobsToWait(keys.concat(args));

return keys.concat(args);
}

/**
* Looks for unlocked jobs in the active queue.
*
* The job was being worked on, but the worker process died and it failed to renew the lock.
* We call these jobs 'stalled'. This is the most common case. We resolve these by moving them
* back to wait to be re-processed. To prevent jobs from cycling endlessly between active and wait,
* (e.g. if the job handler keeps crashing),
* we limit the number stalled job recoveries to settings.maxStalledCount.
*/
async moveStalledJobsToWait(): Promise<[string[], string[]]> {
const client = await this.queue.client;

const args = this.moveStalledJobsToWaitArgs();

return (<any>client).moveStalledJobsToWait(args);
}

/**
Expand Down

0 comments on commit 0fb9b85

Please sign in to comment.