Sha256: 0f010e84feecb1149f0f7a48d2c65f44be720b4cfaf8e16ecd4386d8dae55c44

Contents?: true

Size: 932 Bytes

Versions: 2

Compression:

Stored size: 932 Bytes

Contents

require 'rosetta_queue/consumer_managers/base'
require 'mq'

module RosettaQueue

  class EventedManager < BaseManager

    def start
      EM.run {
        trap_interruptions

        begin
          @consumers.each do |key, consumer|
            RosettaQueue.logger.info("Running consumer #{key} in event machine...")
            consumer.receive
          end
        rescue Exception => e
          RosettaQueue.logger.error("Exception thrown: #{$!}\n" + e.backtrace.join("\n\t"))
        end
      }
    end

    def stop
      RosettaQueue.logger.info("Shutting down event machine...")
      EM.stop
    end

    private

      def trap_interruptions
        trap("INT") {
          RosettaQueue.logger.warn("Interrupt received.  Shutting down...")
          EM.stop
        }

        trap("TERM") {
          RosettaQueue.logger.warn("Interrupt received.  Shutting down...")
          EM.stop
        }
      end

  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
bmabey-rosetta_queue-0.3.3 lib/rosetta_queue/consumer_managers/evented.rb
rosetta_queue-0.4.0 lib/rosetta_queue/consumer_managers/evented.rb