Sha256: 5fac9ac344a433a87e142e2e19f26cd668ee8204eac4d711f22dd0409744bac4
Contents?: true
Size: 1.74 KB
Versions: 10
Compression:
Stored size: 1.74 KB
Contents
# typed: ignore # Copyright (c) 2015 Sqreen. All Rights Reserved. # Please refer to our terms for more information: https://www.sqreen.com/terms.html 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
10 entries across 10 versions & 1 rubygems