Skip to content

Commit 90763fd

Browse files
authored
fix: remove stalled job when finishing fixes OptimalBits#1600
1 parent 6ba0ddf commit 90763fd

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

lib/commands/moveToFinished-7.lua lib/commands/moveToFinished-8.lua

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
KEYS[6] active event key
1515
1616
KEYS[7] delayed key
17+
KEYS[8] stalled key
1718
1819
ARGV[1] jobId
1920
ARGV[2] timestamp
@@ -40,6 +41,7 @@ if rcall("EXISTS", KEYS[3]) == 1 then -- // Make sure job exists
4041
local lockKey = KEYS[3] .. ':lock'
4142
if rcall("GET", lockKey) == ARGV[5] then
4243
rcall("DEL", lockKey)
44+
rcall("SREM", KEYS[8], ARGV[1])
4345
else
4446
return -2
4547
end

lib/getters.js

+10
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ module.exports = function(Queue) {
9090
return this.getJobCountByTypes('wait', 'paused');
9191
};
9292

93+
/**
94+
*
95+
* @returns the potential stalled jobs. Only useful for tests.
96+
*/
97+
Queue.prototype.getStalledCount = function() {
98+
const key = this.toKey('stalled');
99+
return this.client.scard(key);
100+
};
101+
102+
93103
// TO BE DEPRECATED --->
94104
Queue.prototype.getPausedCount = function() {
95105
return this.getJobCountByTypes('paused');

lib/scripts.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ const scripts = {
125125
queueKeys.wait,
126126
queueKeys.priority,
127127
queueKeys.active + '@' + queue.token,
128-
queueKeys.delayed
128+
queueKeys.delayed,
129+
queueKeys.stalled
129130
];
130131

131132
if (typeof shouldRemove === 'boolean') {

test/test_queue.js

+33
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,39 @@ describe('Queue', () => {
14801480
.catch(done);
14811481
});
14821482

1483+
it('should clear job from stalled set when job completed', (done) => {
1484+
const queue2 = utils.buildQueue('running-job-' + uuid.v4(), {
1485+
settings: {
1486+
stalledInterval: 10
1487+
}
1488+
});
1489+
1490+
queue2.process(job => {
1491+
expect(job.data.foo).to.be.equal('bar');
1492+
return delay(100);
1493+
});
1494+
1495+
queue2.add({ foo: 'bar' }).then(
1496+
job => {
1497+
expect(job.id).to.be.ok;
1498+
expect(job.data.foo).to.be.eql('bar');
1499+
},
1500+
err => {
1501+
done(err);
1502+
}
1503+
);
1504+
1505+
queue2.once('completed', async () => {
1506+
const stalled = await queue2.getStalledCount();
1507+
try {
1508+
expect(stalled).to.be.equal(0);
1509+
done();
1510+
} catch (err) {
1511+
done(err);
1512+
}
1513+
});
1514+
});
1515+
14831516
it('process a job that fails', done => {
14841517
const jobError = new Error('Job Failed');
14851518

0 commit comments

Comments
 (0)