Class: Lita::Timing::Scheduled
- Inherits:
-
Object
- Object
- Lita::Timing::Scheduled
- Defined in:
- lib/lita/timing/scheduled.rb
Constant Summary collapse
- ONE_WEEK_IN_SECONDS =
60 * 60 * 24 * 7
Instance Method Summary collapse
- #daily_at(time, days = nil, &block) ⇒ Object
-
#initialize(name, redis) ⇒ Scheduled
constructor
A new instance of Scheduled.
- #weekly_at(time, day, &block) ⇒ Object
Constructor Details
Instance Method Details
#daily_at(time, days = nil, &block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/lita/timing/scheduled.rb', line 14 def daily_at(time, days = nil, &block) @mutex.syncronise do days ||= [:monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday] last_run_at = get_last_run_at next_run = calc_next_daily_run(time, days, last_run_at) if next_run < Time.now yield set_last_run_at end end end |
#weekly_at(time, day, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/lita/timing/scheduled.rb', line 26 def weekly_at(time, day, &block) @mutex.syncronise do last_run_at = get_last_run_at next_run = calc_next_weekly_run(time, day, last_run_at) if next_run < Time.now yield set_last_run_at end end end |