Skip to content

Commit

Permalink
feat(worker): add a public method to run the stalled checker
Browse files Browse the repository at this point in the history
  • Loading branch information
manast committed Feb 23, 2023
1 parent f71ec03 commit 3159266
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/classes/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,7 @@ export class Worker<
}

async run() {
if (!this.stalledCheckTimer && !this.opts.skipStalledCheck) {
await this.runStalledJobsCheck();
this.stalledCheckTimer = setInterval(() => {
this.runStalledJobsCheck();
}, this.opts.stalledInterval);
}
await this.startStalledCheckTimer();

if (this.processFn) {
if (!this.running) {
Expand Down Expand Up @@ -791,6 +786,27 @@ export class Worker<
return this.closing;
}

/**
*
* Manually starts the stalled checker.
* The check will run once as soon as this method is called, and
* then every opts.stalledInterval milliseconds until the worker is closed.
* Note: Normally you do not need to call this method, since the stalled checker
* is automatically started when the worker starts processing jobs after
* calling run. However if you want to process the jobs manually you need
* to call this method to start the stalled checker.
*
* @see {@link https://docs.bullmq.io/patterns/manually-fetching-jobs}
*/
async startStalledCheckTimer(): Promise<void> {
if (!this.stalledCheckTimer && !this.opts.skipStalledCheck) {
await this.runStalledJobsCheck();
this.stalledCheckTimer = setInterval(() => {
this.runStalledJobsCheck();
}, this.opts.stalledInterval);
}
}

/**
* Returns a promise that resolves when active jobs are cleared
*
Expand Down

0 comments on commit 3159266

Please sign in to comment.