Search code examples
rubyruby-on-rails-4recurrenceice-cubesucker-punch

Quick explanation of recurrence rules via ice_cube for fist of fury/ sucker punch


This is probably not the brightest question... feeling especially dense about this. I'm using a really nifty gem, Fist of Fury, to do recurring background tasks with Sucker Punch: https://github.com/facto/fist_of_fury. As the author of the gem states, recurrence rules are built using the ice cube gem https://github.com/seejohnrun/ice_cube.

He gives an example of a recurring job as such:

class SayHiJob
  include SuckerPunch::Job
  include FistOfFury::Recurrent

  recurs { minutely }

  def perform
    Rails.logger.info 'Hi!'
  end
end

I read thru the docs for Fist of Fury and Ice Cube, both as linked above, and just want to confirm my understanding...

  • Fist of fury requires an Ice Cube rule to be in the recurs {} brackets, the recurs is essentially a replacement of schedule from Ice Cube
  • You can use a predefined rule from Ice Cube, such as minutely in the example or daily(2) (every other day), or you can define your own rules
  • If you define your own rules, you can just put it right above the recur, since ice cube's gem is already installed with Fist of Fury, something like (causes activity to happen every 13th of the month):

    rule = Rule.monthly.day_of_month(13) recurs { rule }

If the latter is right, I'd love to know how to write a rule for specific time of day. Something like rule = Rule.daily(2).time_of_day(3) means I want the activity to happen every other day at 3am.


Solution

  • You should be able to use IceCube time validations like:

    hour_of_day(3).minute_of_hour(15).second_of_minute(0)

    Hope that helps!