lib/choria/orchestrator.rb in choria-colt-0.5.1 vs lib/choria/orchestrator.rb in choria-colt-0.6.0
- old
+ new
@@ -37,24 +37,28 @@
def tasks_support
@tasks_support ||= MCollective::Util::Choria.new.tasks_support
end
- def run(task, targets: nil, targets_with_classes: nil, verbose: false) # rubocop:disable Metrics/AbcSize
+ def run(task, targets: nil, targets_with_classes: nil, verbose: false)
rpc_client.progress = verbose
+ discover(targets: targets, targets_with_classes: targets_with_classes)
+ raise DiscoverError, 'No requests sent, no nodes discovered' if rpc_client.discover.size.zero?
- logger.debug "Running task: '#{task.name}' (targets: #{targets.nil? ? 'all' : targets})"
+ task.run
+ end
+
+ def discover(targets: nil, targets_with_classes: nil)
+ logger.debug "Targets: #{targets.nil? ? 'all' : targets})"
targets&.each { |target| rpc_client.identity_filter target }
unless targets_with_classes.nil?
logger.debug "Filtering targets with classes: #{targets_with_classes}"
targets_with_classes.each { |klass| rpc_client.class_filter klass }
end
logger.info 'Discovering targets…'
- raise DiscoverError, 'No requests sent, no nodes discovered' if rpc_client.discover.size.zero?
-
- task.run
+ rpc_client.discover
end
def rpc_client
@rpc_client ||= rpcclient('bolt_tasks', options: {})
end