lib/bolt/transport/base.rb in bolt-2.7.0 vs lib/bolt/transport/base.rb in bolt-2.8.0

- old
+ new

@@ -30,11 +30,11 @@ # Target. # # Transports that need their own batching, like the Orch transport, can # instead override the batches() method to split Targets into sets that can # be executed together, and override the batch_task() and related methods - # to execute a batch of nodes. In that case, those Transports should accept + # to execute a batch of targets. In that case, those Transports should accept # a block argument and call it with a :node_start event for each Target # before executing, and a :node_result event for each Target after # execution. class Base attr_reader :logger @@ -88,44 +88,60 @@ # The default implementations of batch_* strictly assume the transport is # using the default batch size of 1. This method ensures that is the # case and raises an error if it's not. def assert_batch_size_one(method, targets) if targets.length > 1 - message = "#{self.class.name} must implement #{method} to support batches (got #{targets.length} nodes)" + message = "#{self.class.name} must implement #{method} to support batches (got #{targets.length} targets)" raise NotImplementedError, message end end - # Runs the given task on a batch of nodes. + # Runs the given task on a batch of targets. # # The default implementation only supports batches of size 1 and will fail otherwise. # # Transports may override this method to implement their own batch processing. def batch_task(targets, task, arguments, options = {}, &callback) assert_batch_size_one("batch_task()", targets) target = targets.first with_events(target, callback, 'task') do - @logger.debug { "Running task run '#{task}' on #{target.safe_name}" } + @logger.debug { "Running task '#{task.name}' on #{target.safe_name}" } run_task(target, task, arguments, options) end end - # Runs the given command on a batch of nodes. + # Runs the given task on a batch of targets with variable parameters. # # The default implementation only supports batches of size 1 and will fail otherwise. # + # Transports may override this method to implment their own batch processing. + def batch_task_with(targets, task, target_mapping, options = {}, &callback) + assert_batch_size_one("batch_task_with()", targets) + target = targets.first + arguments = target_mapping[target] + + with_events(target, callback, 'task') do + @logger.debug { "Running task '#{task.name}' on #{target.safe_name} with '#{arguments.to_json}'" } + run_task(target, task, arguments, options) + end + end + + # Runs the given command on a batch of targets. + # + # The default implementation only supports batches of size 1 and will fail otherwise. + # # Transports may override this method to implement their own batch processing. def batch_command(targets, command, options = {}, &callback) assert_batch_size_one("batch_command()", targets) target = targets.first with_events(target, callback, 'command') do @logger.debug("Running command '#{command}' on #{target.safe_name}") run_command(target, command, options) end end - # Runs the given script on a batch of nodes. + # Runs the given script on a batch of targets. # # The default implementation only supports batches of size 1 and will fail otherwise. # # Transports may override this method to implement their own batch processing. def batch_script(targets, script, arguments, options = {}, &callback) @@ -135,11 +151,11 @@ @logger.debug { "Running script '#{script}' on #{target.safe_name}" } run_script(target, script, arguments, options) end end - # Uploads the given source file to the destination location on a batch of nodes. + # Uploads the given source file to the destination location on a batch of targets. # # The default implementation only supports batches of size 1 and will fail otherwise. # # Transports may override this method to implement their own batch processing. def batch_upload(targets, source, destination, options = {}, &callback) @@ -155,10 +171,10 @@ assert_batch_size_one("connected?()", targets) connected?(targets.first) end # Split the given list of targets into a list of batches. The default - # implementation returns single-node batches. + # implementation returns single-target batches. # # Transports may override this method, and the corresponding batch_* # methods, to implement their own batch processing. def batches(targets) targets.map { |target| [target] }