plainblack / ving

An opinionated web services starter for Nuxt3 that provides REST and per-field privileges out of the box.
https://plainblack.github.io/ving/
58 stars 7 forks source link

Can't have duplicate cron specs in redis. #175

Closed perlDreamer closed 2 weeks ago

perlDreamer commented 2 weeks ago

https://docs.bullmq.io/guide/jobs/repeatable

Bull is smart enough not to add the same repeatable job if the repeat options are the same.

Steps to repeat.

1) Disable all job handlers. 2) Add cron jobs

./ving.mjs jobs -a Test -c '0 6 * * 2'
./ving.mjs jobs -a Test -c '0 6 * * 3'
./ving.mjs jobs -a Test -c '0 6 * * 2'

I'd expect to see 3 jobs for Test, two that run at the same time and another a different time, but this only makes 2 jobs. I think this is because the Redis key name is probably identical between the two different cron specs.

This is affecting the Hardware Schedules, because there may be a lot of different equipment with jobs that are all done on the 1st day of the month, end of the week, etc.

rizen commented 2 weeks ago

What if the management for cron jobs was handled by ving itself.

When you try to enqueue a cron job, what you are really doing is writing to a database table in ving (not TGCv).

There would then be a job handler called RepeatRunner that would be installed into BullMQ to run on the set schedule. Each time it executes, it would look at the ving table for repeatable jobs and run each of the jobs associated with that schedule.

perlDreamer commented 2 weeks ago

That sounds pretty reasonable and is better than anything else I've though of so far. There's just fine details to consider though, like removing the RepeatRunner with a certain cron spec when the last job with that spec is removed from the table, and making sure that one failing job never prevents other from running, etc.

rizen commented 2 weeks ago

Added Cron Jobs subsystem.