bolt-modules/boltlib/lib/puppet/functions/run_command.rb in bolt-2.34.0 vs bolt-modules/boltlib/lib/puppet/functions/run_command.rb in bolt-2.35.0
- old
+ new
@@ -65,16 +65,34 @@
# Ensure that given targets are all Target instances
targets = inventory.get_targets(targets)
if targets.empty?
call_function('debug', "Simulating run_command('#{command}') - no targets given - no action taken")
- r = Bolt::ResultSet.new([])
+ Bolt::ResultSet.new([])
else
- r = executor.run_command(targets, command, options, Puppet::Pops::PuppetStack.top_of_stack)
- end
+ r = if executor.in_parallel
+ require 'concurrent'
+ require 'fiber'
+ future = Concurrent::Future.execute do
+ executor.run_command(targets,
+ command,
+ options,
+ Puppet::Pops::PuppetStack.top_of_stack)
+ end
- if !r.ok && !options[:catch_errors]
- raise Bolt::RunFailure.new(r, 'run_command', command)
+ Fiber.yield('unfinished') while future.incomplete?
+ future.value || future.reason
+ else
+ executor.run_command(targets,
+ command,
+ options,
+ Puppet::Pops::PuppetStack.top_of_stack)
+ end
+
+ if !r.ok && !options[:catch_errors]
+ raise Bolt::RunFailure.new(r, 'run_command', command)
+ end
+
+ r
end
- r
end
end