gjcarneiro / yacron

A modern Cron replacement that is Docker-friendly
MIT License
449 stars 38 forks source link

add support for smaller time units, like in Systemd timer or Monit #92

Open maxadamo opened 6 months ago

maxadamo commented 6 months ago

Description

Monit has the ability to schedule jobs per seconds, and now with Systemd timer, it's possible to set a lower accuracy for a job and then schedule a job to run every x seconds or microseconds.

I don't know if microseconds is doable with an interpreted language, but I think that providing an option to run a jobs every x second would be nice and it would be a remarkable improvement to Vixie Cron.

s-light commented 1 week ago

as i just found out https://stackoverflow.com/a/43066502/574981

cron only has a resolution of 1 minute (there are other tools I think that may have finer resolutions but they are not standard on unix).

i just switched from supercronic to yacron as i like the yaml syntax very much.. and supercronic just supports it..

parse-crontab supports seconds.

as fare as i can tell it would be needed to be added to

maybe that is already all?!

if so i think i can write a pullrequest for this ;-)

gjcarneiro commented 1 week ago

May be a bit more tricky than that. The yacron main loop is a bit more lax:

  1. Test each job crontab, does it match the current minute? If so, start it
  2. Calculate how many seconds do we need to sleep until the start of the next minute
  3. Sleep those seconds
  4. Go back to step 1.

To support second precision, yacron would need to:

  1. wake up every second, instead of every minute
  2. the part "test each job crontab, does it match the current minute" would need to be tweaked:
    1. some cron jobs are specified with only minute precision, they should not "match" every second in one minute interval, otherwise they would be started 60 times per minute, we don't want that
    2. only the subset of the jobs that actually specify sub-minute precision should be allowed to test for a match multiple times per minute.

Personally I don't find it useful, but YMMV, and I wouldn't mind reviewing some code to do this.