Class: Daemon::ManagementCommands

Inherits:
Object
  • Object
show all
Includes:
Utils::Loggable
Defined in:
lib/onapp/engine/management_commands.rb

Constant Summary

COMMAND_TTL =

TTL for rabbitmq message

3000
CALLBACKS =

Available commands

%w(
start_command
stop_command
reload_command

Instance Attribute Summary

Attributes included from Utils::Loggable

#logger

Instance Method Summary (collapse)

Methods included from Utils::Loggable

#debug, #error, #fatal, #info, #lwarn

Constructor Details

- (ManagementCommands) initialize

Returns a new instance of ManagementCommands



15
16
17
18
19
20
21
22
# File 'lib/onapp/engine/management_commands.rb', line 15

def initialize
  @queue = Daemon::Messaging.queue(Daemon.config.management_queue_name,
                                   message_ttl: COMMAND_TTL)
  @exchange = Daemon::Messaging.channel.fanout(Daemon.config.broadcast_exchange_name)

  @logger = Daemon.logger
  @facility = 'Management'
end

Instance Method Details

- (Object) subscribe

Subscribes to queue, and bind it to all-machines-wide exchange



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/onapp/engine/management_commands.rb', line 25

def subscribe
  return if @subscribed

  info { "Binding to broadcast exchange #{Daemon.config.broadcast_exchange_name}" }
  info { "Subscribed to queue #{Daemon.config.management_queue_name}" }
  @queue
    .bind(@exchange)
    .subscribe(ack: false) do |, payload|
      invoke_callbacks(payload.to_s)
    end

  @subscribed = true
rescue => ex
  error { "Can't subscribe to queue. #{ex.class}: #{ex.message}\n#{ex.backtrace.join("\n")}" }
end