Class: PushyDaemon::Shouter

Inherits:
BmcDaemonLib::MqEndpoint
  • Object
show all
Includes:
BmcDaemonLib::LoggerHelper, NewRelic::Agent::Instrumentation::ControllerInstrumentation
Defined in:
lib/pushyd/shouter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conn, config_shout) ⇒ Shouter

Returns a new instance of Shouter.



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
41
42
43
44
45
# File 'lib/pushyd/shouter.rb', line 16

def initialize(conn, config_shout)
  # Init
  @shouter_keys = []
  @channel = nil
  @exchange = nil

  # Prepare logger
  log_pipe :shouter

  # Check config
  unless config_shout && config_shout.any? && config_shout.is_a?(Enumerable)
    log_error "prepare: empty [shout] section"
    return
  end

  # Extract information
  @shouter_keys = config_shout[:keys] if config_shout[:keys].is_a? Array
  @shouter_topic = config_shout[:topic]
  @shouter_period = config_shout[:period].to_i
  @shouter_period = 1 unless (@shouter_period > 0)

  fail PushyDaemon::EndpointTopicContext unless @shouter_topic

  # Create channel and exchange
  @channel = conn.create_channel
  @exchange = @channel.topic(@shouter_topic, durable: true, persistent: true)

  # Start working, now
  log_info "Shouter initialized, starting loop now", { topic: @shouter_topic, period: @shouter_period, keys: @shouter_keys }
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



14
15
16
# File 'lib/pushyd/shouter.rb', line 14

def logger
  @logger
end

#tableObject

Class options



13
14
15
# File 'lib/pushyd/shouter.rb', line 13

def table
  @table
end

Instance Method Details

#start_loopObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/pushyd/shouter.rb', line 47

def start_loop
  # Prepare exchange
  loop do
    # Generate payload
    payload = {time: Time.now.to_f, host: BmcDaemonLib::Conf.host}
    # payload = nil

    # Shout it !
    exchange_shout @exchange, payload
    sleep @shouter_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