Module: DaemonObjects::AmqpSupport
- Defined in:
- lib/daemon_objects/amqp/runner.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#prefetch ⇒ Object
Returns the value of attribute prefetch.
-
#queue ⇒ Object
Returns the value of attribute queue.
-
#retry_wait_time ⇒ Object
Returns the value of attribute retry_wait_time.
-
#worker_class ⇒ Object
Returns the value of attribute worker_class.
Instance Method Summary collapse
Instance Attribute Details
#endpoint ⇒ Object
Returns the value of attribute endpoint.
2 3 4 |
# File 'lib/daemon_objects/amqp/runner.rb', line 2 def endpoint @endpoint end |
#prefetch ⇒ Object
Returns the value of attribute prefetch.
2 3 4 |
# File 'lib/daemon_objects/amqp/runner.rb', line 2 def prefetch @prefetch end |
#queue ⇒ Object
Returns the value of attribute queue.
2 3 4 |
# File 'lib/daemon_objects/amqp/runner.rb', line 2 def queue @queue end |
#retry_wait_time ⇒ Object
Returns the value of attribute retry_wait_time.
2 3 4 |
# File 'lib/daemon_objects/amqp/runner.rb', line 2 def retry_wait_time @retry_wait_time end |
#worker_class ⇒ Object
Returns the value of attribute worker_class.
2 3 4 |
# File 'lib/daemon_objects/amqp/runner.rb', line 2 def worker_class @worker_class end |
Instance Method Details
#arguments ⇒ Object
5 6 7 |
# File 'lib/daemon_objects/amqp/runner.rb', line 5 def arguments @arguments ||= {} end |
#run ⇒ Object
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 41 42 43 44 45 |
# File 'lib/daemon_objects/amqp/runner.rb', line 13 def run logger.info "Preparing to start the AMQP watcher." connection = Bunny.new(endpoint) connection.start Signal.trap("INT") do logger.info "Received signal 'INT'. Exiting process" connection.close { EventMachine.stop } exit end logger.info "Starting up the AMQP watcher." channel = connection.create_channel channel.prefetch(1) if prefetch worker = worker_class.new( channel, get_consumer, { :queue_name => queue, :logger => logger, :arguments => arguments }) worker.start logger.info "AMQP worker started" rescue Bunny::InternalError, Bunny::TCPConnectionFailed => e logger.error(e) && e.backtrace.join("\n") wait && retry end |
#wait ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/daemon_objects/amqp/runner.rb', line 47 def wait = "* Retrying connection in #{retry_wait_time} seconds .... *" sleep(retry_wait_time) logger.info("\n") logger.info("*" * .length) logger.info() logger.info("*" * .length) logger.info("\n") end |