class UV::Repeat
Public Class Methods
new(scheduler, every)
click to toggle source
Calls superclass method
UV::ScheduledEvent::new
# File lib/uv-rays/scheduler.rb, line 104 def initialize(scheduler, every) super(scheduler) @every = every next_time end
Public Instance Methods
pause()
click to toggle source
removes the event from the schedule
# File lib/uv-rays/scheduler.rb, line 123 def pause @paused = true @scheduler.unschedule(self) end
resume()
click to toggle source
reschedules the event to the next time period can be used to reset a repeating timer
# File lib/uv-rays/scheduler.rb, line 130 def resume @paused = false @last_scheduled = @reactor.now reschedule end
trigger()
click to toggle source
Runs the event and reschedules
Calls superclass method
UV::ScheduledEvent#trigger
# File lib/uv-rays/scheduler.rb, line 137 def trigger super() @reactor.next_tick do # Do this next tick to avoid needless scheduling # if the event is stopped in the callback reschedule end end
update(every, timezone: nil)
click to toggle source
Update the time period of the repeating event
@param schedule [String] a standard CRON job line or a human readable string representing a time period.
# File lib/uv-rays/scheduler.rb, line 114 def update(every, timezone: nil) time = Scheduler.parse_in(every, :quiet) || Scheduler.parse_cron(every, :quiet, timezone: timezone) raise ArgumentError.new("couldn't parse \"#{o}\"") if time.nil? @every = time reschedule end
Protected Instance Methods
info()
click to toggle source
# File lib/uv-rays/scheduler.rb, line 167 def info "repeat:#{@every.inspect}" end
next_time()
click to toggle source
# File lib/uv-rays/scheduler.rb, line 150 def next_time @last_scheduled = @reactor.now if @every.is_a? Integer @next_scheduled = @last_scheduled + @every else # must be a cron @next_scheduled = (@every.next.to_f * 1000).to_i - @scheduler.time_diff end end
reschedule()
click to toggle source
# File lib/uv-rays/scheduler.rb, line 160 def reschedule unless @paused next_time @scheduler.reschedule(self) end end