Class: Houston::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/houston/boot/timer.rb

Instance Method Summary collapse

Constructor Details

#initializeTimer

Returns a new instance of Timer.



34
35
36
37
38
39
40
# File 'lib/houston/boot/timer.rb', line 34

def initialize
  @queued_timers = Concurrent::Array.new

  Houston.observer.on "daemon:scheduler:start", raise: true do
    schedule_queued_timers!
  end
end

Instance Method Details

#every(interval, &block) ⇒ Object

Raises:

  • (ArgumentError)


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