Multiple Cron Jobs

export const jobs = (app: Elysia) => app
.use(cron({
name: 'job_1',
pattern: '*/10 * * * * *',
run() { console.log('job 1') }
}))
.use(cron({
name: 'job_2',
pattern: '*/10 * * * * *',
run() { console.log('job 2') }
}))
.post("/jobs/trigger", ({ store: { cron: { job_1, job_2} }}) => {
console.log("triggering jobs")
job_1.trigger()
job_2.trigger()
})
export const jobs = (app: Elysia) => app
.use(cron({
name: 'job_1',
pattern: '*/10 * * * * *',
run() { console.log('job 1') }
}))
.use(cron({
name: 'job_2',
pattern: '*/10 * * * * *',
run() { console.log('job 2') }
}))
.post("/jobs/trigger", ({ store: { cron: { job_1, job_2} }}) => {
console.log("triggering jobs")
job_1.trigger()
job_2.trigger()
})
Anyone here have experience with multiple cron jobs? This creates 2 jobs that both run, yet when I try to manually trigger them job_1.trigger() works and job_2.trigger() errors undefined is not an object (evaluating 'job_2.trigger')
Solution:
For those seeing this in the future, it is a bug, see https://github.com/elysiajs/elysia-cron/pull/4 for potential fix
GitHub
Fix multi cron by rsromanowski · Pull Request #4 · elysiajs/elysia-...
Context Setting up multiple cron jobs would allow both to run, but you could only reference the first one declared. The reason for this is subsequent calls to app.state('cron'...) (which oc...
Jump to solution
2 Replies
whatplan
whatplan15mo ago
Not sure if that is something supported by the cron plugin Probably would be best to make an issue there: https://github.com/elysiajs/elysia-cron
GitHub
GitHub - elysiajs/elysia-cron: Plugin for Elysia that add support f...
Plugin for Elysia that add support for running cronjob - GitHub - elysiajs/elysia-cron: Plugin for Elysia that add support for running cronjob
Solution
Rich
Rich15mo ago
For those seeing this in the future, it is a bug, see https://github.com/elysiajs/elysia-cron/pull/4 for potential fix
GitHub
Fix multi cron by rsromanowski · Pull Request #4 · elysiajs/elysia-...
Context Setting up multiple cron jobs would allow both to run, but you could only reference the first one declared. The reason for this is subsequent calls to app.state('cron'...) (which oc...
Want results from more Discord servers?
Add your server