Skip to content

Commit

Permalink
Merge 09db1c9 into b14fe62
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciusestevam committed May 24, 2021
2 parents b14fe62 + 09db1c9 commit 44f177b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ class Queue {
return job
}

removeRepeatable(name, repeat) {
const queue = this.get(name)

return queue.bull.removeRepeatable('__default__', repeat)
}

getRepeatableJobs(name) {
const queue = this.get(name)
const jobs = queue.bull.getRepeatableJobs()

return jobs
}

schedule(name, data, date, options) {
let delay

Expand Down
64 changes: 64 additions & 0 deletions test/unit/queue.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,68 @@ test.group('Bull', (group) => {
assert.equal('Invalid schedule time', err.message)
}
})

test('should get all repeatable jobs', async (assert) => {
ioc.bind('Test/Bull', () => {
return class {
static get key() {
return 'TestBull-name'
}

async handle() {}
}
})

const bull = new Queue(
console,
ioc.use('Config'),
['Test/Bull'],
ioc,
resolver
)
const Job = ioc.use('Test/Bull')
const data = { test: 'data' }
const repeat = { cron: '* * * * *' }

await bull.add(Job.key, data, { repeat })

const jobs = await bull.getRepeatableJobs(Job.key)

assert.equal(jobs.length, 1)
assert.deepEqual(repeat.cron, jobs[0].cron)
})

test('should remove a repeatable job', async (assert) => {
ioc.bind('Test/Bull', () => {
return class {
static get key() {
return 'TestBull-name'
}

async handle() {}
}
})

const bull = new Queue(
console,
ioc.use('Config'),
['Test/Bull'],
ioc,
resolver
)
const Job = ioc.use('Test/Bull')
const data = { test: 'data' }
const repeat = { cron: '* * * * *' }

await bull.add(Job.key, data, { repeat })

let jobs = await bull.getRepeatableJobs(Job.key)
assert.equal(jobs.length, 1)
assert.deepEqual(repeat.cron, jobs[0].cron)

await bull.removeRepeatable(Job.key, repeat)

jobs = await bull.getRepeatableJobs(Job.key)
assert.equal(jobs.length, 0)
})
})

0 comments on commit 44f177b

Please sign in to comment.