class Proxy::Dynflow::Ticker

Attributes

clock[R]

Public Class Methods

new(clock, logger, refresh_interval) click to toggle source
# File lib/smart_proxy_dynflow/ticker.rb, line 9
def initialize(clock, logger, refresh_interval)
  @clock = clock
  @logger = logger
  @events = []
  @refresh_interval = refresh_interval
  plan_next_tick
end

Public Instance Methods

add_event(target, args) click to toggle source
# File lib/smart_proxy_dynflow/ticker.rb, line 28
def add_event(target, args)
  @events << [target, args]
  plan_next_tick
end
tick() click to toggle source
# File lib/smart_proxy_dynflow/ticker.rb, line 17
def tick
  @logger.debug("Ticker ticking for #{@events.size} events")
  @events.each do |(target, args)|
    pass_event(target, args)
  end
  @events = []
ensure
  @planned = false
  plan_next_tick
end

Private Instance Methods

pass_event(target, args) click to toggle source
# File lib/smart_proxy_dynflow/ticker.rb, line 35
def pass_event(target, args)
  target.tell(args)
rescue => e
  @logger.error("Failed passing event to #{target} with #{args}")
  @logger.error(e)
end
plan_next_tick() click to toggle source
# File lib/smart_proxy_dynflow/ticker.rb, line 42
def plan_next_tick
  if !@planned && !@events.empty?
    @clock.ping(reference, Time.now.getlocal + @refresh_interval, :tick)
    @planned = true
  end
end