Sha256: 67ca4d7d705f0e538ed2124827afdc70dd9c09283e28aa6c977ece28bd5166cc

Contents?: true

Size: 808 Bytes

Versions: 1

Compression:

Stored size: 808 Bytes

Contents

# Provides common behavior shared by the Bunny and HotBunnies dispatchers.
class Woodhouse::Dispatchers::CommonAmqpDispatcher < Woodhouse::Dispatcher

  private

  # Yields an AMQP channel to the block, doing any error handling or synchronization
  # necessary.
  def run(&blk)
    raise NotImplementedError
  end

  def deliver_job(job)
    run do |client|  
      exchange = client.exchange(job.exchange_name, :type => :headers)
      publish_job(job, exchange)
    end
  end

  def deliver_job_update(job, data)
    run do |client|
      exchange = client.exchange("woodhouse.progress", :type => :direct)
      client.queue(job.job_id, :arguments => {"x-expires" => 5*60*1000}).bind(exchange, :routing_key => job.job_id)
      exchange.publish(data.to_json, :routing_key => job.job_id)
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
woodhouse-1.0.0 lib/woodhouse/dispatchers/common_amqp_dispatcher.rb