Sha256: a510fa00ce89fde373ced806a8ac61493a1421918d90ecd672587e06e68ca516

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require 'evrone/common/amqp'

module Evrone::CI::Worker::AMQP

  Base = Struct.new("Subscribing", :app) do
    include Evrone::CI::Worker::Helper::Logger

    def consumer_name
      Thread.current[:consumer_name]
    end

    def consumer_id
      Thread.current[:consumer_id]
    end

    def consumer_tag
      consumer_id ? "#{consumer_name.split('::').last} #{consumer_id}" : consumer_name
    end
  end

  class Subscribing < Base
    def call(env)
      logger.tagged(consumer_tag) do
        logger.warn "subsribing #{env[:exchange].name}"
        rs = app.call env
        logger.warn "shutdown"
        rs
      end
    end
  end

  class Recieving < Base
    def call(env)
      logger.warn "payload recieved #{env[:payload].inspect[0...60]}..."
      rs = app.call env
      logger.warn "commit message"
      rs
    end
  end
end

Evrone::Common::AMQP.configure do |c|
  c.subscribing do
    use Evrone::CI::Worker::AMQP::Subscribing
  end

  c.recieving do
    use Evrone::CI::Worker::AMQP::Recieving
  end

  c.content_type = 'application/x-protobuf'
  c.logger = nil
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
evrone-ci-worker-0.2.0.pre0 lib/evrone/ci/worker/initializers/amqp.rb