Class: UV::Repeat

Inherits:
ScheduledEvent show all
Defined in:
lib/uv-rays/scheduler.rb

Instance Attribute Summary

Attributes inherited from ScheduledEvent

#created, #last_scheduled, #next_scheduled, #trigger_count

Instance Method Summary collapse

Methods inherited from ScheduledEvent

#<=>, #cancel, #inspect, #to_time

Constructor Details

#initialize(scheduler, every) ⇒ Repeat

Returns a new instance of Repeat.



101
102
103
104
105
106
# File 'lib/uv-rays/scheduler.rb', line 101

def initialize(scheduler, every)
    super(scheduler)

    @every = every
    next_time
end

Instance Method Details

#pause ⇒ Object

removes the event from the schedule



120
121
122
123
# File 'lib/uv-rays/scheduler.rb', line 120

def pause
    @paused = true
    @scheduler.unschedule(self)
end

#resume ⇒ Object

reschedules the event to the next time period can be used to reset a repeating timer



127
128
129
130
131
# File 'lib/uv-rays/scheduler.rb', line 127

def resume
    @paused = false
    @last_scheduled = @reactor.now
    reschedule
end

#trigger ⇒ Object

Runs the event and reschedules



134
135
136
137
138
139
140
141
# File 'lib/uv-rays/scheduler.rb', line 134

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) ⇒ Object

Update the time period of the repeating event

Parameters:

  • schedule (String) —

    a standard CRON job line or a human readable string representing a time period.

Raises:

  • (ArgumentError)


111
112
113
114
115
116
117
# File 'lib/uv-rays/scheduler.rb', line 111

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