Class: PushyDaemon::Shouter
- Includes:
- NewRelic::Agent::Instrumentation::ControllerInstrumentation
- Defined in:
- lib/pushyd/shouter.rb
Constant Summary
Constants included from Shared::LoggerHelper
Shared::LoggerHelper::CONFIG_PATH
Instance Attribute Summary collapse
-
#table ⇒ Object
Returns the value of attribute table.
Attributes inherited from Endpoint
Instance Method Summary collapse
-
#initialize ⇒ Shouter
constructor
A new instance of Shouter.
- #shout ⇒ Object
Methods included from Shared::LoggerHelper
Constructor Details
#initialize ⇒ Shouter
Returns a new instance of Shouter.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pushyd/shouter.rb', line 12 def initialize # Init super @keys = [] # Check config config_shout = Conf[:shout] unless config_shout && config_shout.any? && config_shout.is_a?(Enumerable) log_error "prepare: empty [shout] section" return end # Extract information @keys = config_shout[:keys] if config_shout[:keys].is_a? Array @topic = config_shout[:topic] @period = config_shout[:period] || 0 # Start connexion to RabbitMQ and create channel @channel = connect_channel Conf.amqp log_info "channel connected" # Create exchange fail PushyDaemon::EndpointTopicContext unless @topic @exchange = @channel.topic(@topic, durable: true, persistent: true) # Send shouter info to logs shouter_info = { topic: @topic, period: @period, keys: @keys } log_info "shouter initialized", shouter_info end |
Instance Attribute Details
#table ⇒ Object
Returns the value of attribute table.
10 11 12 |
# File 'lib/pushyd/shouter.rb', line 10 def table @table end |
Instance Method Details
#shout ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/pushyd/shouter.rb', line 42 def shout return unless @exchange # Prepare exchange loop do random_string = SecureRandom.hex random_key = @keys.sample || "random" channel_shout [:ping, random_key, random_string], {dummy: true, time: Time.now.to_f, host: Conf.host} sleep @period end rescue AMQ::Protocol::EmptyResponseError => e fail PushyDaemon::ShouterResponseError, "#{e.class} (#{e.inspect})" rescue Bunny::ChannelAlreadyClosed => e fail PushyDaemon::ShouterChannelClosed, "#{e.class} (#{e.inspect})" rescue Bunny::PreconditionFailed => e fail PushyDaemon::ShouterPreconditionFailed, "#{e.class} (#{e.inspect})" rescue Interrupt => e @channel.close fail PushyDaemon::ShouterInterrupted, e.class end |