Class: MotherBrain::Gear::Service::Action Private

Inherits:
Object
  • Object
show all
Includes:
MB::Mixin::Services
Defined in:
lib/mb/gears/service/action.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, component, &block) ⇒ Action

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Action.

Parameters:

Raises:



15
16
17
18
19
20
21
22
23
# File 'lib/mb/gears/service/action.rb', line 15

def initialize(name, component, &block)
  unless block_given?
    raise ArgumentError, "block required for action '#{name}' on component '#{component.name}'"
  end

  @name      = name
  @component = component
  @block     = block
end

Instance Attribute Details

#nameString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


9
10
11
# File 'lib/mb/gears/service/action.rb', line 9

def name
  @name
end

Instance Method Details

#run(job, environment, nodes, run_chef = true) ⇒ Service::Action

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Run this action on the specified nodes.

Parameters:

  • job (MB::Job)

    a job to update with status

  • environment (String)

    the environment this command is being run on

  • nodes (Array<Ridley::Node>)

    the nodes to run this action on

Returns:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/mb/gears/service/action.rb', line 35

def run(job, environment, nodes, run_chef = true)
  job.set_status("Running component: #{component.name} service action: #{name} on #{nodes.collect(&:name).join(', ')}")

  runner = Service::ActionRunner.new(environment, nodes, &block)
  runner.run(job)

  if run_chef || runner.toggle_callbacks.any?
    node_querier.bulk_chef_run(job, nodes, runner.service_recipe)
  end

  self
ensure
  runner.reset(job)
end