class DoubleDecker::Agent
Attributes
end_time[R]
id[R]
Public Class Methods
new(bus, bus_data, expected_agents)
click to toggle source
# File src/double_decker/agent.rb, line 5 def initialize(bus, bus_data, expected_agents) @bus = bus @bus_data = bus_data @expected_agents = expected_agents @finished = nil @id = setup! merge({}) end
Public Instance Methods
finish!(end_time = DateTime.now)
click to toggle source
# File src/double_decker/agent.rb, line 36 def finish!(end_time = DateTime.now) @end_time = end_time @finished&.call(to_h) if last @bus.finished&.call(@bus_data.to_h) @bus_data.teardown_bus end end
merge(hash)
click to toggle source
# File src/double_decker/agent.rb, line 14 def merge(hash) @bus_data.merge(id, hash) end
on_finished(&block)
click to toggle source
# File src/double_decker/agent.rb, line 22 def on_finished(&block) @finished = block end
to_h()
click to toggle source
# File src/double_decker/agent.rb, line 18 def to_h @bus_data.to_h[id.to_s] end
wait_for_expected_agents(max_tries=0)
click to toggle source
# File src/double_decker/agent.rb, line 26 def wait_for_expected_agents(max_tries=0) if @expected_agents loop do break if (@bus_data.active_agents == @expected_agents.to_i) || (max_tries == 5) sleep 1 max_tries += 1 end end end
Private Instance Methods
last()
click to toggle source
# File src/double_decker/agent.rb, line 47 def last teardown!.zero? end
setup!()
click to toggle source
# File src/double_decker/agent.rb, line 55 def setup! @bus_data.setup_agent end
teardown!()
click to toggle source
# File src/double_decker/agent.rb, line 51 def teardown! @bus_data.teardown_agent end