Module: Kitchen::Command::RunAction

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

Overview

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

Author:

Instance Method Summary collapse

Instance Method Details

#run_action(action, instances, *args) ⇒ Object

Run an instance action (create, converge, setup, verify, destroy) on a collection of instances. 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

  • instances (Array<Instance>)

    an array of instances



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/kitchen/command.rb', line 161

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

  queue = Queue.new
  instances.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(&:join)
end