Skip to content

Commit

Permalink
feat: emit event on job lock extend failure
Browse files Browse the repository at this point in the history
  • Loading branch information
bewithjonam committed Oct 31, 2021
1 parent 57471d2 commit 7247b3b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
6 changes: 6 additions & 0 deletions REFERENCE.md
Expand Up @@ -955,6 +955,12 @@ A queue emits also some useful events:
// workers that crash or pause the event loop.
})

.on('lock-extension-failed', function (job, err) {
// A job failed to extend lock. This will be useful to debug redis
// connection issues and jobs getting restarted because workers
// are not able to extend locks.
});

.on('progress', function (job, progress) {
// A job's progress was updated!
})
Expand Down
4 changes: 2 additions & 2 deletions lib/queue.js
Expand Up @@ -1078,8 +1078,8 @@ Queue.prototype.processJob = function(job, notFetch = false) {
lockExtender();
}
})
.catch((/*err*/) => {
// Somehow tell the worker this job should stop processing...
.catch(err => {
this.emit('lock-extension-failed', job, err);
});
}
);
Expand Down
21 changes: 21 additions & 0 deletions test/test_events.js
Expand Up @@ -211,6 +211,27 @@ describe('events', () => {
});
});

it('should emit an event if a job fails to extend lock', done => {
const LOCK_RENEW_TIME = 1;
queue = utils.buildQueue('queue fails to extend lock', {
settings: {
lockRenewTime: LOCK_RENEW_TIME
}
});
queue.once('lock-extension-failed', (lockingFailedJob, error) => {
expect(lockingFailedJob.data.foo).to.be.equal('lockingFailedJobFoo');
expect(error.message).to.be.equal('Connection is closed.');
queue.close().then(done);
});
queue.isReady().then(() => {
queue.process(() => {
utils.simulateDisconnect(queue);
return delay(LOCK_RENEW_TIME + 0.25);
});
queue.add({ foo: 'lockingFailedJobFoo' });
});
});

it('should listen to global events', done => {
const queue1 = utils.buildQueue();
const queue2 = utils.buildQueue();
Expand Down

0 comments on commit 7247b3b

Please sign in to comment.