Class: JobQueue::BeanstalkAdapter
- Inherits:
-
Object
- Object
- JobQueue::BeanstalkAdapter
- Defined in:
- lib/job_queue/adapters/beanstalk_adapter.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ BeanstalkAdapter
constructor
A new instance of BeanstalkAdapter.
- #put(string) ⇒ Object
- #subscribe(error_report, &block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ BeanstalkAdapter
Returns a new instance of BeanstalkAdapter.
4 5 6 7 8 |
# File 'lib/job_queue/adapters/beanstalk_adapter.rb', line 4 def initialize( = {}) host = [:host] || 'localhost' port = [:port] || 11300 @beanstalk = Beanstalk::Pool.new(["#{host}:#{port}"]) end |
Instance Method Details
#put(string) ⇒ Object
10 11 12 |
# File 'lib/job_queue/adapters/beanstalk_adapter.rb', line 10 def put(string) @beanstalk.put(string) end |
#subscribe(error_report, &block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/job_queue/adapters/beanstalk_adapter.rb', line 14 def subscribe(error_report, &block) loop do begin job = @beanstalk.reserve JobQueue.logger.info "Beanstalk received #{job.body}" yield job.body job.delete rescue Beanstalk::DeadlineSoonError => e error_report.call(job, e) rescue => e error_report.call(job.body, e) end end end |