Class: SerialScheduler::Producer
- Inherits:
-
Object
- Object
- SerialScheduler::Producer
- Defined in:
- lib/serial_scheduler.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#next ⇒ Object
readonly
Returns the value of attribute next.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize(name, timeout:, interval: nil, cron: nil, &block) ⇒ Producer
constructor
A new instance of Producer.
- #next! ⇒ Object
- #start(now) ⇒ Object
Constructor Details
#initialize(name, timeout:, interval: nil, cron: nil, &block) ⇒ Producer
Returns a new instance of Producer.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/serial_scheduler.rb', line 11 def initialize(name, timeout:, interval: nil, 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 |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
9 10 11 |
# File 'lib/serial_scheduler.rb', line 9 def block @block end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/serial_scheduler.rb', line 9 def name @name end |
#next ⇒ Object (readonly)
Returns the value of attribute next.
9 10 11 |
# File 'lib/serial_scheduler.rb', line 9 def next @next end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
9 10 11 |
# File 'lib/serial_scheduler.rb', line 9 def timeout @timeout end |
Instance Method Details
#next! ⇒ Object
37 38 39 40 41 42 43 |
# 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) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# 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 |