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

Constructor Details

#initialize(scheduler, every) ⇒ Repeat

Returns a new instance of Repeat.



76
77
78
79
80
81
# File 'lib/uv-rays/scheduler.rb', line 76

def initialize(scheduler, every)
    super(scheduler)

    @every = every
    next_time
end

Instance Method Details

#pauseObject

removes the event from the schedule



95
96
97
98
# File 'lib/uv-rays/scheduler.rb', line 95

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

#resumeObject

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



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

def resume
    @paused = false
    reschedule
end

#triggerObject

Runs the event and reschedules



108
109
110
111
112
113
114
115
# File 'lib/uv-rays/scheduler.rb', line 108

def trigger
    super()
    @loop.next_tick do
        # Do this next tick to avoid needless scheduling

        # if the event is stopped in the callback

        reschedule
    end
end

#update(every) ⇒ 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)


86
87
88
89
90
91
92
# File 'lib/uv-rays/scheduler.rb', line 86

def update(every)
    time = parse_in(every, :quiet) || parse_cron(every, :quiet)
    raise ArgumentError.new("couldn't parse \"#{o}\"") if time.nil?

    @every = time
    reschedule
end