lib/bolt/executor.rb in bolt-1.26.0 vs lib/bolt/executor.rb in bolt-1.27.0

- old
+ new

@@ -38,11 +38,11 @@ val.new end end end @reported_transports = Set.new - @subscribers = Set.new + @subscribers = {} @publisher = Concurrent::SingleThreadExecutor.new @noop = noop @run_as = nil @pool = if concurrency > 0 @@ -59,17 +59,20 @@ # If there was an error creating the transport, ensure it gets thrown impl.no_error! impl.value end - def subscribe(subscriber) - @subscribers << subscriber + def subscribe(subscriber, types = nil) + @subscribers[subscriber] = types self end def publish_event(event) - @subscribers.each do |subscriber| + @subscribers.each do |subscriber, types| + # If types isn't set or if the subscriber is subscribed to + # that type of event, publish the event + next unless types.nil? || types.include?(event[:type]) @publisher.post(subscriber) do |sub| sub.handle_event(event) end end end @@ -184,13 +187,11 @@ def report_function_call(function) @analytics&.event('Plan', 'call_function', label: function) end def report_bundled_content(mode, name) - if @analytics.bundled_content&.include?(name) - @analytics&.event('Bundled Content', mode, label: name) - end + @analytics.report_bundled_content(mode, name) end def report_apply(statement_count, resource_counts) data = { statement_count: statement_count } @@ -243,11 +244,11 @@ description = options.fetch('_description', "script #{script}") log_action(description, targets) do options = { '_run_as' => run_as }.merge(options) if run_as batch_execute(targets) do |transport, batch| - with_node_logging("Running script #{script} with '#{arguments}'", batch) do + with_node_logging("Running script #{script} with '#{arguments.to_json}'", batch) do transport.batch_script(batch, script, arguments, options, &method(:publish_event)) end end end end @@ -257,10 +258,10 @@ log_action(description, targets) do options = { '_run_as' => run_as }.merge(options) if run_as arguments['_task'] = task.name batch_execute(targets) do |transport, batch| - with_node_logging("Running task #{task.name} with '#{arguments}'", batch) do + with_node_logging("Running task #{task.name} with '#{arguments.to_json}'", batch) do transport.batch_task(batch, task, arguments, options, &method(:publish_event)) end end end end