class SerialScheduler::Producer
Attributes
block[R]
name[R]
next[R]
timeout[R]
Public Class Methods
new(name, interval: nil, timeout:, cron: nil, &block)
click to toggle source
# File lib/serial_scheduler.rb, line 11 def initialize(name, interval: nil, timeout:, cron: nil, &block) if cron cron = Fugit.do_parse_cron(cron) elsif !interval || interval < 1 || !interval.is_a?(Integer) raise ArgumentError end @name = name @interval = interval @cron = cron @timeout = timeout @block = block @next = nil end
Public Instance Methods
next!()
click to toggle source
# File lib/serial_scheduler.rb, line 37 def next! if @cron @next = @cron.next_time(Time.at(@next)).to_i else @next += @interval end end
start(now)
click to toggle source
# File lib/serial_scheduler.rb, line 26 def start(now) @next = if @cron @cron.next_time(Time.at(now)).to_i else # interval 1s: do not wait # interval 1d: if we are 1 hour into the day next execution is in 23 hours now + (@interval - (now % @interval) - 1) end end