你试过hourly(2)吗?
recurrence do
hourly(2)
# if you want to specify the exactly minute or minutes
# `minute_of_hour(30, ...)`
# hourly(2).minute_of_hour(30)
end
在icecube's README,但我还没试过。
你也可以这样做:
recurrence do
# set recurrence to [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]
daily.hour_of_day(*(0..23).to_a.select { |hour_of_day| hour_of_day.even? })
end
但是恕我直言hourly(2) 是更好的选择。
没有 Sidetiq 的另一种选择是在结束 perform 方法之前添加 self.perform_in(2.hours)。
def perform
# ...
self.class.perform_in(2.hours)
end
更新:
https://github.com/tobiassvn/sidetiq/wiki/Known-Issues
不幸的是,使用 ice_cube 的间隔方法在启动时非常慢(它往往会在很长一段时间内消耗 100% 的 CPU)和每次重复运行。这是因为它会计算自计划开始时间以来的所有可能事件。
所以,最好使用更明确的方式:
recurrence { hourly.minute_of_hour(0, 15, 30, 45) }