mirror of
https://github.com/OptimalBits/bull.git
synced 2026-07-02 00:17:41 +08:00
fix(repeat): remove last delayed job
This commit is contained in:
+1
-1
@@ -22,13 +22,13 @@ rules:
|
||||
no-alert: 2
|
||||
no-console: [2, { allow: ['warn', 'error'] }]
|
||||
no-underscore-dangle: 0
|
||||
object-shorthand: 0
|
||||
|
||||
strict: [2, 'global']
|
||||
no-var: 2
|
||||
prefer-arrow-callback: 2
|
||||
prefer-const: 2
|
||||
no-inner-declarations: 0
|
||||
object-shorthand: [2, 'consistent-as-needed']
|
||||
newline-per-chained-call: 2
|
||||
|
||||
mocha/no-exclusive-tests: 2
|
||||
|
||||
+10
-2
@@ -113,14 +113,22 @@ module.exports = function(Queue) {
|
||||
};
|
||||
|
||||
Queue.prototype.removeRepeatableByKey = function(repeatJobKey) {
|
||||
const data = this._keyToData(repeatJobKey);
|
||||
const repeatMeta = this._keyToData(repeatJobKey);
|
||||
const queueKey = this.keys[''];
|
||||
|
||||
const jobId = repeatMeta.id ? repeatMeta.id + ':' : ':';
|
||||
const repeatJobId = getRepeatJobId(
|
||||
repeatMeta.name || Job.DEFAULT_JOB_NAME,
|
||||
jobId,
|
||||
'',
|
||||
md5(repeatJobKey)
|
||||
);
|
||||
|
||||
return this.isReady().then(() => {
|
||||
return this.client.removeRepeatable(
|
||||
this.keys.repeat,
|
||||
this.keys.delayed,
|
||||
data.id,
|
||||
repeatJobId,
|
||||
repeatJobKey,
|
||||
queueKey
|
||||
);
|
||||
|
||||
+71
-15
@@ -57,6 +57,49 @@ describe('repeat', () => {
|
||||
.catch(done);
|
||||
});
|
||||
|
||||
it('should add a repetable job when using stardDate and endDate', async () => {
|
||||
const job1 = await queue.add(
|
||||
{
|
||||
name: 'job1'
|
||||
},
|
||||
{
|
||||
repeat: {
|
||||
cron: '0 * * * * *',
|
||||
startDate: '2020-09-02T22:29:00Z'
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
expect(job1).to.exist;
|
||||
expect(job1.opts).to.have.property('repeat');
|
||||
expect(job1.opts.repeat).to.be.deep.equal({
|
||||
count: 1,
|
||||
cron: '0 * * * * *',
|
||||
startDate: '2020-09-02T22:29:00Z'
|
||||
});
|
||||
|
||||
const job2 = await queue.add(
|
||||
{
|
||||
name: 'job2'
|
||||
},
|
||||
{
|
||||
repeat: {
|
||||
cron: '0 * * * * *',
|
||||
startDate: '2020-09-02T22:29:00Z',
|
||||
endDate: '2020-09-05T01:44:37Z'
|
||||
}
|
||||
}
|
||||
);
|
||||
expect(job2).to.exist;
|
||||
expect(job2.opts).to.have.property('repeat');
|
||||
expect(job2.opts.repeat).to.be.deep.equal({
|
||||
count: 1,
|
||||
cron: '0 * * * * *',
|
||||
startDate: '2020-09-02T22:29:00Z',
|
||||
endDate: '2020-09-05T01:44:37Z'
|
||||
});
|
||||
});
|
||||
|
||||
it('should get repeatable jobs with different cron pattern', done => {
|
||||
const crons = [
|
||||
'10 * * * * *',
|
||||
@@ -414,23 +457,36 @@ describe('repeat', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to remove repeatable jobs by key', () => {
|
||||
it('should be able to remove repeatable jobs by key', async () => {
|
||||
const repeat = { cron: '*/2 * * * * *' };
|
||||
|
||||
return queue.add('remove', { foo: 'bar' }, { repeat }).then(() => {
|
||||
return queue
|
||||
.getRepeatableJobs()
|
||||
.then(repeatableJobs => {
|
||||
expect(repeatableJobs).to.have.length(1);
|
||||
return queue.removeRepeatableByKey(repeatableJobs[0].key);
|
||||
})
|
||||
.then(() => {
|
||||
return queue.getRepeatableJobs();
|
||||
})
|
||||
.then(repeatableJobs => {
|
||||
expect(repeatableJobs).to.have.length(0);
|
||||
});
|
||||
});
|
||||
await queue.add('remove', { foo: 'bar' }, { repeat });
|
||||
|
||||
const repeatableJobs = await queue.getRepeatableJobs();
|
||||
expect(repeatableJobs).to.have.length(1);
|
||||
await queue.removeRepeatableByKey(repeatableJobs[0].key);
|
||||
|
||||
const repeatableJobs2 = await queue.getRepeatableJobs();
|
||||
expect(repeatableJobs2).to.have.length(0);
|
||||
|
||||
const delayedJobs = await queue.getDelayed();
|
||||
expect(delayedJobs).to.have.length(0);
|
||||
});
|
||||
|
||||
it('should be able to remove repeatable jobs by key that has a jobId', async () => {
|
||||
const repeat = { cron: '*/2 * * * * *' };
|
||||
|
||||
await queue.add('remove', { foo: 'bar' }, { jobId: 'qux', repeat });
|
||||
|
||||
const repeatableJobs = await queue.getRepeatableJobs();
|
||||
expect(repeatableJobs).to.have.length(1);
|
||||
await queue.removeRepeatableByKey(repeatableJobs[0].key);
|
||||
|
||||
const repeatableJobs2 = await queue.getRepeatableJobs();
|
||||
expect(repeatableJobs2).to.have.length(0);
|
||||
|
||||
const delayedJobs = await queue.getDelayed();
|
||||
expect(delayedJobs).to.have.length(0);
|
||||
});
|
||||
|
||||
it('should allow removing a customId repeatable job', function(done) {
|
||||
|
||||
Reference in New Issue
Block a user