Class: Drmap::BeanstalkWorker
- Inherits:
-
Object
- Object
- Drmap::BeanstalkWorker
- Defined in:
- lib/drmap/beanstalk_worker.rb
Instance Method Summary collapse
- #fail!(e) ⇒ Object
-
#initialize(pool) ⇒ BeanstalkWorker
constructor
A new instance of BeanstalkWorker.
- #next_job ⇒ Object
- #process ⇒ Object
- #save(jid, result) ⇒ Object
- #success! ⇒ Object
Constructor Details
#initialize(pool) ⇒ BeanstalkWorker
Returns a new instance of BeanstalkWorker.
4 5 6 |
# File 'lib/drmap/beanstalk_worker.rb', line 4 def initialize(pool) @pool = pool end |
Instance Method Details
#fail!(e) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/drmap/beanstalk_worker.rb', line 31 def fail!(e) puts "ERROR #{e.message}" e.backtrace.each do |msg| pp msg end @job.bury end |
#next_job ⇒ Object
22 23 24 25 |
# File 'lib/drmap/beanstalk_worker.rb', line 22 def next_job @job = @pool.next_job @job.ybody end |
#process ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/drmap/beanstalk_worker.rb', line 8 def process loop do begin job_payload = next_job pp job_payload result = eval(job_payload[:proc]).call(job_payload[:data]) save(job_payload[:jid], result) success! rescue => e fail!(e) end end end |
#save(jid, result) ⇒ Object
39 40 41 42 |
# File 'lib/drmap/beanstalk_worker.rb', line 39 def save(jid, result) @pool.put_result(jid, result) pp [@job[:pid], jid, result] end |
#success! ⇒ Object
27 28 29 |
# File 'lib/drmap/beanstalk_worker.rb', line 27 def success! @job.delete end |