I am trying to schedule jobs usign the agenda
library. I've done this:
await this.agenda.start()
this.agenda.define(scheduler.id, { lockLifetime: 10000 }, (job, done) => {
console.log('Hello world!')
//some logic using values on job variable
done()
})
const result = await this.agenda.every(scheduler.cron, scheduler.id, scheduler, { startDate: new Date() })
await this.agenda.start() //i added start here too just in case
console.log(result)
That last console.log shows that the job was created successfully and it even saves on database, but the nextRunAt
defaults to 1st of january 2022 for some reason (as seen on the full object below). I tried adding the startDate
on the every()
call but it still shows 2022 and i have no idea why. No matter what cron
i send it still doesnt work. The only param i send to Agenda
constructor is the database, nothing about when to start.
Thanks!
Job {
agenda: Agenda {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
_findAndLockNextJob: [Function: findAndLockNextJob],
_name: undefined,
_processEvery: 5000,
_defaultConcurrency: 5,
_maxConcurrency: 20,
_defaultLockLimit: 0,
_lockLimit: 0,
_definitions: { '61af764f8f26fb369c76b571': [Object] },
_runningJobs: [],
_lockedJobs: [],
_jobQueue: JobProcessingQueue { _queue: [] },
_defaultLockLifetime: 600000,
_sort: { nextRunAt: 1, priority: -1 },
_indices: { name: 1, nextRunAt: 1, priority: -1, lockedAt: 1, disabled: 1 },
_isLockingOnTheFly: false,
_isJobQueueFilling: Map(0) {},
_jobsToLock: [],
_ready: Promise { undefined },
_db: MongoClient {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
s: [Object],
topology: [Topology],
[Symbol(kCapture)]: false,
[Symbol(options)]: [Object: null prototype]
},
_mdb: Db { s: [Object] },
_collection: Collection { s: [Object] },
_processInterval: Timeout {
_idleTimeout: 5000,
_idlePrev: [TimersList],
_idleNext: [TimersList],
_idleStart: 28573,
_onTimeout: [Function: bound processJobs],
_timerArgs: undefined,
_repeat: 5000,
_destroyed: false,
[Symbol(refed)]: true,
[Symbol(kHasPrimitive)]: false,
[Symbol(asyncId)]: 221,
[Symbol(triggerId)]: 0
},
[Symbol(kCapture)]: false
},
attrs: {
name: '61af764f8f26fb369c76b571',
data: {
//stuff that i use here
},
priority: 0,
type: 'single',
nextRunAt: 2022-01-01T03:00:00.000Z, //next run at 2022
repeatInterval: '* * * 1 *',
repeatTimezone: null,
startDate: 2021-12-07T14:57:19.394Z,
endDate: null,
skipDays: null,
_id: new ObjectId("61af764fcb12102f92e637dc")
}
}