Sha256: 883c316e8d1469aea06b92d5a05eecb2c84a9ecc2a03e74161a5bee75b9b512f
Contents?: true
Size: 1.59 KB
Versions: 6
Compression:
Stored size: 1.59 KB
Contents
require 'sqreen/ecosystem/loggable' module Sqreen module Ecosystem module ModuleApi module MessageProducer include Loggable # method for ecosystem to inject the config # @param [Sqreen::Ecosystem::TracingBroker] attr_writer :tracing_broker private def determine_interest(type, hints = {}) @tracing_broker.interested_consumers(type, hints) end def publish(data, interested) @tracing_broker.publish(data, interested) end # Convenience wrapper. # Wraps a callback, skipping it if there is no interest in the type # produced and submitting the return value as a message to the # tracing broker def wrap_for_interest(type, gen_hints = nil, &block) raise ArgumentError, 'no block passed' if block.nil? proc do |*args| hints = gen_hints[*args] if gen_hints interested = determine_interest(type, hints || {}) unless interested logger.debug { "No interested consumers in #{type}" } next end res = block[*args] next if res.nil? if res.is_a?(Array) res.each do |d| raise "unexpected return type: #{d.class}" unless d.is_a?(type) @tracing_broker.publish(d, interested) end else raise "unexpected return type: #{res.class}" unless res.is_a?(type) @tracing_broker.publish(res, interested) end end end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems