Skip to content

Commit

Permalink
feat(job): expose extendLock as a public method
Browse files Browse the repository at this point in the history
  • Loading branch information
manast committed Jan 6, 2021
1 parent 6e9a359 commit 17e8431
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/classes/job.ts
Expand Up @@ -207,6 +207,16 @@ export class Job<T = any, R = any, N extends string = string> {
}
}

/**
* Extend the lock for this job.
*
* @param token unique token for the lock
* @param duration lock duration in milliseconds
*/
async extendLock(token: string, duration: number) {
return Scripts.extendLock(this.queue, this.id, token, duration);
}

/**
* Moves a job to the completed queue.
* Returned job to be used with Queue.prototype.nextJobFromJobData.
Expand Down
14 changes: 7 additions & 7 deletions src/classes/scripts.ts
Expand Up @@ -91,18 +91,18 @@ export class Scripts {
return (<any>client).removeJob(keys.concat([queue.keys.events, jobId]));
}

static async extendLock<T, R, N extends string>(
worker: Worker<T, R, N>,
static async extendLock(
queue: QueueBase,
jobId: string,
token: string,
duration: number,
) {
const client = await worker.client;
const opts: WorkerOptions = worker.opts;
const client = await queue.client;
const args = [
worker.toKey(jobId) + ':lock',
worker.keys.stalled,
queue.toKey(jobId) + ':lock',
queue.keys.stalled,
token,
opts.lockDuration,
duration,
jobId,
];
return (<any>client).extendLock(args);
Expand Down
2 changes: 1 addition & 1 deletion src/classes/worker.ts
Expand Up @@ -272,7 +272,7 @@ export class Worker<
this.opts.lockRenewTime,
async () => {
try {
const result = await Scripts.extendLock(this, job.id, token);
const result = await job.extendLock(token, this.opts.lockDuration);
if (result && !timerStopped) {
lockExtender();
}
Expand Down

0 comments on commit 17e8431

Please sign in to comment.