Create combinatorial schedule rules with ice_cube gem

534 Views Asked by At

Lets say I want a task to be scheduled every 6 hours on one day a week, every 2 weeks. How would I achieve this? I've used hour_of_day to add a specific hour to a weekly rule, but I'd like to avoid having to calculate each specific hour based off of the interval and start time, and adding them individually. Is it possible to chain rules? Like an hourly rule on top of a weekly one? When I add them as two separate rules, the hourly one fires independent of the weekly one, i.e. on days that wouldn't satisfy the weekly rule.

1

There are 1 best solutions below

1
yez On

If you want a task to simply run at a certain time, have you considered setting up a cron that invokes your script?

Read about cron and how to use it here

But, if you're totally invested in ice_cube, it seems that their documentation shows chaining is possible.

This might be what you need:

schedule.add_recurrence_rule IceCube::Rule.weekly(2).day(:monday, :tuesday).hourly(6)