Skip to content

Commit

Permalink
Options are not passed correct when scheduling jobs (#523)
Browse files Browse the repository at this point in the history
* Add failing test for passing metdata to schedule

* Spread options
  • Loading branch information
janmeier authored Dec 5, 2024
1 parent ea91e88 commit 57b74cc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/timekeeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class Timekeeper extends EventEmitter {
const scheduled = schedules
.filter(i => this.shouldSendIt(i.cron, i.timezone))
.map(({ name, data, options }) =>
({ name: QUEUES.SEND_IT, data: { name, data, options }, singletonKey: name, singletonSeconds: 60 }))
({ name: QUEUES.SEND_IT, data: { name, data, ...options }, singletonKey: name, singletonSeconds: 60 }))

if (scheduled.length > 0 && !this.stopped) {
await this.manager.insert(scheduled)
Expand Down
27 changes: 27 additions & 0 deletions test/scheduleTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,33 @@ describe('schedule', function () {
await boss.stop({ graceful: false })
})

it('should set job metadata correctly', async function () {
const config = {
...this.test.bossConfig,
cronMonitorIntervalSeconds: 1,
cronWorkerIntervalSeconds: 1,
noDefault: true
}

let boss = await helper.start(config)
const queue = this.test.bossConfig.schema

await boss.createQueue(queue)
await boss.schedule(queue, '* * * * *', {}, { retryLimit: 42 })
await boss.stop({ graceful: false })

boss = await helper.start({ ...config, schedule: true })

await delay(2000)

const [job] = await boss.fetch(queue, { includeMetadata: true })

assert(job)

assert.strictEqual(job.retryLimit, 42)
await boss.stop({ graceful: false })
})

it('should not enable scheduling if archive config is < 60s', async function () {
const config = {
...this.test.bossConfig,
Expand Down

0 comments on commit 57b74cc

Please sign in to comment.