Class: ScheduleRunner
- Defined in:
- lib/abstractivator/schedule/schedule_runner.rb
Overview
Performs an action periodically, but only at times allowed by a Schedule.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(task, action) ⇒ ScheduleRunner
constructor
A new instance of ScheduleRunner.
- #run_after(seconds_to_wait) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(task, action) ⇒ ScheduleRunner
Returns a new instance of ScheduleRunner.
13 14 15 16 |
# File 'lib/abstractivator/schedule/schedule_runner.rb', line 13 def initialize(task, action) @task = task @action = action end |
Class Method Details
.run_on_schedule(task, &action) ⇒ Object
9 10 11 |
# File 'lib/abstractivator/schedule/schedule_runner.rb', line 9 def self.run_on_schedule(task, &action) ScheduleRunner.new(task, action).start end |
Instance Method Details
#run_after(seconds_to_wait) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/abstractivator/schedule/schedule_runner.rb', line 22 def run_after(seconds_to_wait) @task.before_waiting(seconds_to_wait) @task.pump.add_timer(seconds_to_wait) do schedule = @task.schedule if schedule.permits?(Time.now) @action.call run_after(@task.interval_seconds) else run_after(schedule.downtime_minutes_from(Time.now) * 60) end end end |
#start ⇒ Object
18 19 20 |
# File 'lib/abstractivator/schedule/schedule_runner.rb', line 18 def start run_after(@task.interval_seconds) end |