Class: Houston::Timer
- Inherits:
-
Object
- Object
- Houston::Timer
- Defined in:
- lib/houston/boot/timer.rb
Instance Method Summary collapse
- #every(interval, &block) ⇒ Object
-
#initialize ⇒ Timer
constructor
A new instance of Timer.
- #stop(interval, block) ⇒ Object
Constructor Details
Instance Method Details
#every(interval, &block) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/houston/boot/timer.rb', line 42 def every(interval, &block) return schedule_later :every, interval, block unless $scheduler match = Attentive::Matcher.match!(TRIGGER_PHRASE, interval) raise ArgumentError, "Unrecognized interval: #{interval.inspect}" unless match method_name, argument = match["houston.trigger.every"] $scheduler.public_send method_name, argument, &block end |
#stop(interval, block) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/houston/boot/timer.rb', line 51 def stop(interval, block) return queued_timers.delete [:every, interval, block] unless $scheduler # Look up the job by its handler # Note: this doesn't check `interval`. Conceivably, two jobs could be # set up at different intervals that both invoke the same block. job = $scheduler.jobs.detect { |job| job.handler == block } job.unschedule end |