Is there a way to prevent duplicate cron jobs from running?

#44 · closed · 2 comments

View on GitHub ↗

johnnncodes

On cron, I'm using Flock ( https://linux.die.net/man/1/flock ). Here's my Clockfile: ```ruby using RubyClock::DSL every('5 seconds') do rake('hello:world') end ``` Assuming hello:world rake task can take long to finish running and I don't want to run it if previous run is still running, how can I do that using ruby-clock gem?

Comments

johnnncodes

Closing. I just figured out that `rake` is blocking by default: [synchronize](https://github.com/jjb/ruby-clock/blob/main/lib/ruby-clock/rake.rb#L33)

jjb

hey @johnnncodes, glad you figured it out regarding this and https://github.com/jjb/ruby-clock/issues/45 - another option is rufus-scheduler `overlap: false` option https://github.com/jmettraux/rufus-scheduler?tab=readme-ov-file#overlap-false with that, you can specify that individual rake tasks should not run at the same time as other instances of themselves, while allowing different unrelated rake tasks to run at the same time. you will also avoid threads being "built up" waiting for each other (because without using `overlap: false` and using `rake`, the outer ruby-clock job doesn't have any intelligence so it just queues up jobs, which wait in line for `rake` to finish). let me know if any of that is confusing