class Smith::Commands::Start
Public Instance Methods
execute()
click to toggle source
# File lib/smith/commands/agency/start.rb, line 10 def execute start do |value| responder.succeed(value) end end
start(&blk)
click to toggle source
# File lib/smith/commands/agency/start.rb, line 16 def start(&blk) #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #!!!!!!!!!!!! See note about target at end of this file !!!!!!!!!!!!! #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # Sort out any groups. If the group option is set it will override # any other specified agents. if options[:group] begin agents_to_start = agent_group(options[:group]) if agents_to_start.empty? blk.call("Empty group: #{options[:group]}. No agents started") else start_agents(agents_to_start, &blk) end rescue RuntimeError => e blk.call(e.message) end else start_agents(target, &blk) end end
Private Instance Methods
options_spec()
click to toggle source
# File lib/smith/commands/agency/start.rb, line 64 def options_spec banner "Start an agent/agents or group of agents.", "<agent[s]>" opt :group, "Start everything in the specified group", :type => :string, :short => :g end
start_agents(agents_to_start, &blk)
click to toggle source
# File lib/smith/commands/agency/start.rb, line 41 def start_agents(agents_to_start, &blk) if agents_to_start.empty? blk.call("Start what? No agent specified.") else worker = ->(agent_name, iter) do running_agents = agents.find_by_name(agent_name) if !running_agents.empty? && running_agents.first.singleton iter.return("Agent already running: #{agent_name}") else agent = agents.create(agent_name) agent.start iter.return((agent.state == 'starting') ? "#{agent_name}: #{agent.uuid}" : '') end end done = ->(started_agents) do blk.call(started_agents.compact.join("\n")) end EM::Iterator.new(agents_to_start).map(worker, done) end end