Class: Thor::Jobs::MonitorMaster
- Inherits:
-
Thor::Job
- Object
- Bsl::Application
- Application
- Thor::Job
- Thor::Jobs::MonitorMaster
- Defined in:
- lib/jobs/MonitorMaster-0.0.1/main.rb
Constant Summary collapse
- @@AUTHOR =
"[email protected]"
- @@DESCRIPTION =
"Monitoring node"
- @@LICENSE =
"GPL"
- @@VERSION =
"0.0.1"
- @@SUPPORTED_MSGS =
[]
Instance Attribute Summary
Attributes inherited from Thor::Job
#amqp_conn, #em_conn, #sql_conn, #thread
Attributes inherited from Application
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ MonitorMaster
constructor
C-tor.
-
#main ⇒ Object
Console application main().
-
#run(opts = {}) ⇒ Object
Async runner.
Methods inherited from Thor::Job
author, description, #is_running?, license, #process_msg, #start, #stop, supported_msgs, version
Methods inherited from Application
#amqp_handle_failure, #amqp_loop, #amqp_start, #amqp_stop
Constructor Details
#initialize(opts = {}) ⇒ MonitorMaster
C-tor
13 14 15 |
# File 'lib/jobs/MonitorMaster-0.0.1/main.rb', line 13 def initialize(opts = {}) super(opts) end |
Instance Method Details
#main ⇒ Object
Console application main()
85 86 87 |
# File 'lib/jobs/MonitorMaster-0.0.1/main.rb', line 85 def main super() end |
#run(opts = {}) ⇒ Object
Async runner
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/jobs/MonitorMaster-0.0.1/main.rb', line 18 def run(opts = {}) super(opts) if([:verbose]) Bsl::Logger::Log "Thor::Jobs::MonitorMaster::run()" end # Construct channel_response name channel_response_name = (self.class.name + ".response").downcase if([:channel_response] != nil) channel_response_name = [:channel_response] end queue_response_name = channel_response_name + "." + Thor::generate_guid # Create channel response if([:verbose]) Bsl::Logger::Log "Creating response channel - '#{channel_response_name}'" end channel_response = AMQP::Channel.new(amqp_conn) exchange_response = channel_response.fanout(channel_response_name) # Create and bind response queue if([:verbose]) Bsl::Logger::Log "Creating response queue - '#{queue_response_name}'" end channel_response.queue(queue_response_name, :auto_delete => true).bind(exchange_response).subscribe do |payload| if([:verbose]) Bsl::Logger::Log "Received payload: '#{payload}'" end process_msg(channel_response, exchange_response, payload) end # Construct channel request name channel_request_name = (self.class.name + ".request").downcase if([:channel_request] != nil) channel_request_name = [:channel_request] end # Create request channel if([:verbose]) Bsl::Logger::Log "Creating request channel - '#{channel_request_name}'" end channel_request = AMQP::Channel.new(amqp_conn) exchange_request = channel_request.fanout(channel_request_name) request_interval = 1 if([:request_interval]) request_interval = [:request_interval] end # Publish if([:verbose]) Bsl::Logger::Log "Starting publish, interval #{request_interval} sec(s)." end EventMachine.add_periodic_timer(request_interval) do payload = {:a => "b"}.to_json if([:verbose]) Bsl::Logger::Log "Publishing payload: '#{payload}'" end exchange_request.publish(payload) end end |