Sha256: 58e9bead049830d49efc43d3a37122b82d75845cfe7ef042a8fa00fc5b30724a

Contents?: true

Size: 849 Bytes

Versions: 2

Compression:

Stored size: 849 Bytes

Contents

require 'bunny'
require 'ears/consumer'
require 'ears/setup'
require 'ears/version'

module Ears
  class Error < StandardError
  end

  class << self
    def connection
      @connection ||= Bunny.new.tap { |conn| conn.start }
    end

    def channel
      Thread.current[:ears_channel] ||=
        connection
          .create_channel(nil, 1, true)
          .tap do |channel|
            channel.prefetch(1)
            channel.on_uncaught_exception { |error| Thread.main.raise(error) }
          end
    end

    def setup(&block)
      Ears::Setup.new.instance_eval(&block)
    end

    def run!
      running = true
      Signal.trap('INT') { running = false }
      Signal.trap('TERM') { running = false }
      sleep 1 while running
    end

    def reset!
      @connection = nil
      Thread.current[:ears_channel] = nil
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ears-0.2.0 lib/ears.rb
ears-0.1.0 lib/ears.rb