Module: Polytrix::Command::RunAction

Included in:
Action, Test
Defined in:
lib/polytrix/command.rb

Overview

Common module to execute a Polytrix action such as create, converge, etc.

Instance Method Summary collapse

Instance Method Details

#run_action(_action, scenarios, *_args) ⇒ Object

Run an instance action (create, converge, setup, verify, destroy) on a collection of scenarios. The instance actions will take place in a seperate thread of execution which may or may not be running concurrently.

Parameters:

  • action (String)

    action to perform

  • scenarios (Array<Instance>)

    an array of scenarios



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/polytrix/command.rb', line 104

def run_action(_action, scenarios, *_args)
  concurrency = 1
  if options[:concurrency]
    concurrency = options[:concurrency] || scenarios.size
    concurrency = scenarios.size if concurrency > scenarios.size
  end

  scenarios.each { |i| @queue << i }
  concurrency.times { @queue << nil }

  threads = concurrency.times.map { |i| spawn(i) }
  threads.map do |t|
    begin
      t.join
    rescue Polytrix::ExecutionError, Polytrix::ChallengeFailure
      # respawn thread
      t.kill
      threads.delete(t)
      threads.push(spawn)
    end
  end while threads.any?(&:alive?)
end