Class: MotherBrain::CommandInvoker::Worker

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/mb/command_invoker/worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, environment, node_filter = nil) ⇒ Worker

Returns a new instance of Worker.

Parameters:

  • command (MB::Command)

    command to invoke

  • environment (String)

    environment to invoke this command on

  • node_filter (Array) (defaults to: nil)

    nil

    list of nodes to limit the command to



19
20
21
22
23
# File 'lib/mb/command_invoker/worker.rb', line 19

def initialize(command, environment, node_filter = nil)
  @command     = command
  @environment = environment
  @node_filter = node_filter
end

Instance Attribute Details

#commandMB::Command (readonly)

Returns:



7
8
9
# File 'lib/mb/command_invoker/worker.rb', line 7

def command
  @command
end

#environmentString (readonly)

Returns:

  • (String)


9
10
11
# File 'lib/mb/command_invoker/worker.rb', line 9

def environment
  @environment
end

#node_filterArray (readonly)

Returns:

  • (Array)


11
12
13
# File 'lib/mb/command_invoker/worker.rb', line 11

def node_filter
  @node_filter
end

Instance Method Details

#run(job, arguments = Array.new) ⇒ Object

Parameters:

  • job (MB::Job)
  • arguments (Array) (defaults to: Array.new)


27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mb/command_invoker/worker.rb', line 27

def run(job, arguments = Array.new)
  arguments ||= Array.new

  msg = "Invoking #{command.type} command #{command.scope.name} #{command.name} on #{environment}"
  msg << " with arguments: #{arguments}" if arguments.any?
  job.set_status(msg)

  command.invoke(job, environment, node_filter, *arguments)
rescue RemoteCommandError => ex
  abort(ex)
end