Class: JobQueue::BeanstalkAdapter
- Inherits:
-
Object
- Object
- JobQueue::BeanstalkAdapter
- Defined in:
- lib/job_queue/adapters/beanstalk_adapter.rb
Instance Method Summary collapse
-
#initialize ⇒ BeanstalkAdapter
constructor
A new instance of BeanstalkAdapter.
- #put(string) ⇒ Object
- #subscribe(error_report, &block) ⇒ Object
Constructor Details
#initialize ⇒ BeanstalkAdapter
Returns a new instance of BeanstalkAdapter.
4 5 6 |
# File 'lib/job_queue/adapters/beanstalk_adapter.rb', line 4 def initialize @beanstalk = Beanstalk::Pool.new(['localhost:11300']) end |
Instance Method Details
#put(string) ⇒ Object
8 9 10 |
# File 'lib/job_queue/adapters/beanstalk_adapter.rb', line 8 def put(string) @beanstalk.put(string) end |
#subscribe(error_report, &block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/job_queue/adapters/beanstalk_adapter.rb', line 12 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 |