Sha256: d2058cc07e03626348b22d0881a3c88fbf8f97f74f98df3550c8a81118db9f04

Contents?: true

Size: 1.11 KB

Versions: 5

Compression:

Stored size: 1.11 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
  c.url    = Evrone::CI::Worker.config.amqp_url
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
evrone-ci-worker-0.2.0.pre6 lib/evrone/ci/worker/initializers/amqp.rb
evrone-ci-worker-0.2.0.pre5 lib/evrone/ci/worker/initializers/amqp.rb
evrone-ci-worker-0.2.0.pre4 lib/evrone/ci/worker/initializers/amqp.rb
evrone-ci-worker-0.2.0.pre3 lib/evrone/ci/worker/initializers/amqp.rb
evrone-ci-worker-0.2.0.pre1 lib/evrone/ci/worker/initializers/amqp.rb