Method: God.control

Defined in:
lib/god.rb

.control(name, command) ⇒ Object

Control the lifecycle of the given task(s).

name - The String name of a task/group. If empty, invokes command for all tasks. command - The String command to run. Valid commands are:

"start", "monitor", "restart", "stop", "unmonitor", "remove".

Returns an Array of String task names affected by the command.



459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
# File 'lib/god.rb', line 459

def self.control(name, command)
  # Get the list of items.
  items = self.watches_by_name(name)

  jobs = []

  # Do the command.
  case command
    when "start", "monitor"
      items.each { |w| jobs << Thread.new { w.monitor if w.state != :up } }
    when "restart"
      items.each { |w| jobs << Thread.new { w.move(:restart) } }
    when "stop"
      items.each { |w| jobs << Thread.new { w.action(:stop); w.unmonitor if w.state != :unmonitored } }
    when "unmonitor"
      items.each { |w| jobs << Thread.new { w.unmonitor if w.state != :unmonitored } }
    when "remove"
      items.each { |w| self.unwatch(w) }
    else
      raise InvalidCommandError.new
  end

  jobs.each { |j| j.join }

  items.map { |x| x.name }
end