Sha256: 8eb89ce175a323bf2c96ee797356a10417cd1b0bd99c2f3e9f3de8b60f426bb7

Contents?: true

Size: 573 Bytes

Versions: 1

Compression:

Stored size: 573 Bytes

Contents

require 'beanstalk-client'

class JobQueue::BeanstalkAdapter
  def initialize(options = {})
    host = options[:host] || 'localhost'
    port = options[:port] || 11300
    @beanstalk = Beanstalk::Pool.new(["#{host}:#{port}"])
  end
  
  def put(string)
    @beanstalk.put(string)
  end
  
  def subscribe(error_report, &block)
    loop do
      begin
        job = @beanstalk.reserve
        JobQueue.logger.info "Beanstalk received #{job.body}"
        yield job.body
        job.delete
      rescue => e
        error_report.call(job.body, e)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mloughran-job_queue-0.0.4 lib/job_queue/adapters/beanstalk_adapter.rb