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



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/polytrix/command.rb', line 187

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

  queue = Queue.new
  scenarios.each { |i| queue << i }
  concurrency.times { queue << nil }

  threads = []
  concurrency.times do
    threads << Thread.new do
      while (instance = queue.pop)
        instance.public_send(action, *args)
      end
    end
  end
  threads.map { |i| i.join }
end