Sha256: 69c141c7506bd8663542919e62e9acb4bcec96b3cc6f12331cf9a3d1f10e10f8

Contents?: true

Size: 483 Bytes

Versions: 2

Compression:

Stored size: 483 Bytes

Contents

require 'beanstalk-client'

class JobQueue::BeanstalkAdapter
  def initialize
    @beanstalk = Beanstalk::Pool.new(['localhost:11300'])
  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

2 entries across 2 versions & 2 rubygems

Version Path
mloughran-job_queue-0.0.3 lib/job_queue/adapters/beanstalk_adapter.rb
strobemonkey-job_queue-0.0.5 lib/job_queue/adapters/beanstalk_adapter.rb