Class: Sidekiq::Repeat::MiniIceCube::MainDsl
- Inherits:
-
Object
- Object
- Sidekiq::Repeat::MiniIceCube::MainDsl
- Includes:
- IceCubeDslErrorHandling
- Defined in:
- lib/sidekiq/repeat/mini_ice_cube.rb
Constant Summary
Constants included from IceCubeDslErrorHandling
IceCubeDslErrorHandling::IceCubeSyntaxError
Class Method Summary collapse
Instance Method Summary collapse
Methods included from IceCubeDslErrorHandling
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Sidekiq::Repeat::MiniIceCube::IceCubeDslErrorHandling
Class Method Details
.define_interval_method(name, base, *stars_prefix) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/sidekiq/repeat/mini_ice_cube.rb', line 51 def define_interval_method(name, base, *stars_prefix) define_method(name) do |*args| stars = stars_prefix.dup || [] if args.any? interval = args.first.to_i unsupported("invalid interval: #{interval}") unless interval && interval >= 0 && interval <= base # Instead of always calculating the next() occurrence as ice_cube does, # we can only have fixed run times (as per cron syntax). Hence we calculate # the run times based on integer division of interval and time frame, using # a random start offset based on the remaining time. # # NOTE: This effectivly means that after the last run in the time frame the # next run will be scheduled after interval+remainder. # # Example: minutely(17) will run 3 times per hour. After the last run each # hour the skip will be 17 + 9 = 26 minutes. A random offset in # [0,26) will be applied, so a possible cron line could be '4,21,38'. times = [] nruns = (base / interval).floor rnoff = rand(interval + base % interval).floor runs = nruns.times.map { |i| i * interval + rnoff } stars << runs.map(&:to_s).join(',') end stars.fill('*', stars.size..4) CronSyntax.new(*stars) end end |
Instance Method Details
#weekly(*args) ⇒ Object
84 85 86 87 |
# File 'lib/sidekiq/repeat/mini_ice_cube.rb', line 84 def weekly(*args) unsupported('interval argument unsupported for weekly') unless args.empty? CronSyntax.new(0, 3, '*', '*', 0) # Sundays at 3AM. end |