Skip to content
This repository was archived by the owner on Mar 9, 2023. It is now read-only.

Commit a8c9d87

Browse files
authored
fix(removeJob): remove job from stored jobs (bee-queue#230)
1 parent 52736f5 commit a8c9d87

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/queue.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,12 @@ class Queue extends Emitter {
459459
this.toKey('jobs'),
460460
this.toKey('delayed'),
461461
jobId
462-
).then(() => this);
462+
).then(() => {
463+
if (this.settings.storeJobs) {
464+
this.jobs.delete(jobId);
465+
}
466+
return this;
467+
});
463468

464469
if (cb) helpers.asCallback(promise, cb);
465470
return promise;

test/queue-test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,32 @@ describe('Queue', (it) => {
658658
t.is(jobData, job.toData());
659659
});
660660

661+
it.describe('Remove', (it) => {
662+
it('should remove a job', async (t) => {
663+
const queue = t.context.makeQueue({
664+
getEvents: false,
665+
});
666+
667+
const [job1, job2] = await Promise.all([
668+
queue.createJob().save(),
669+
queue.createJob().save(),
670+
]);
671+
const [ref1, ref2] = await Promise.all([
672+
queue.getJob(job1.id),
673+
queue.getJob(job2.id),
674+
]);
675+
t.is(ref1, job1);
676+
t.is(ref2, job2);
677+
678+
await Promise.all([queue.removeJob(job1.id), job2.remove()]);
679+
680+
t.deepEqual(
681+
await Promise.all([queue.getJob(job1.id), queue.getJob(job2.id)]),
682+
[null, null]
683+
);
684+
});
685+
});
686+
661687
it.describe('Health Check', (it) => {
662688
it('reports a waiting job', async (t) => {
663689
const queue = t.context.makeQueue({

0 commit comments

Comments
 (0)