Class: Drmap::BeanstalkPool
- Inherits:
-
Object
- Object
- Drmap::BeanstalkPool
- Defined in:
- lib/drmap/beanstalk_pool.rb
Class Method Summary collapse
-
.hosts=(bean_hosts) ⇒ Object
Worst design ever!.
Instance Method Summary collapse
-
#initialize ⇒ BeanstalkPool
constructor
A new instance of BeanstalkPool.
- #next_job ⇒ Object
- #next_result(jid) ⇒ Object
- #peers ⇒ Object
- #put_job(jid, proc_str, data) ⇒ Object
- #put_result(jid, result) ⇒ Object
- #watch_jobs ⇒ Object
- #watch_results(jid) ⇒ Object
Constructor Details
#initialize ⇒ BeanstalkPool
Returns a new instance of BeanstalkPool.
9 10 11 |
# File 'lib/drmap/beanstalk_pool.rb', line 9 def initialize @pool = Beanstalk::Pool.new(@@hosts) end |
Class Method Details
.hosts=(bean_hosts) ⇒ Object
Worst design ever!
5 6 7 |
# File 'lib/drmap/beanstalk_pool.rb', line 5 def self.hosts=(bean_hosts) @@hosts = bean_hosts end |
Instance Method Details
#next_job ⇒ Object
17 18 19 20 |
# File 'lib/drmap/beanstalk_pool.rb', line 17 def next_job watch_jobs @pool.reserve end |
#next_result(jid) ⇒ Object
28 29 30 31 32 |
# File 'lib/drmap/beanstalk_pool.rb', line 28 def next_result(jid) watch_results(jid) job = @pool.reserve job_payload = job.ybody[:result] end |
#peers ⇒ Object
13 14 15 |
# File 'lib/drmap/beanstalk_pool.rb', line 13 def peers @pool end |
#put_job(jid, proc_str, data) ⇒ Object
22 23 24 25 26 |
# File 'lib/drmap/beanstalk_pool.rb', line 22 def put_job(jid, proc_str, data) @pool.use("job") payload = {:pid => Process.pid, :jid => jid, :proc => proc_str, :data => data} @pool.yput(payload) end |
#put_result(jid, result) ⇒ Object
34 35 36 37 38 |
# File 'lib/drmap/beanstalk_pool.rb', line 34 def put_result(jid, result) @pool.use("result#{jid}") payload = {:pid => Process.pid, :jid => jid, :result => result} @pool.yput(payload) end |
#watch_jobs ⇒ Object
40 41 42 43 |
# File 'lib/drmap/beanstalk_pool.rb', line 40 def watch_jobs @pool.watch("job") @pool.ignore("default") end |
#watch_results(jid) ⇒ Object
45 46 47 48 49 |
# File 'lib/drmap/beanstalk_pool.rb', line 45 def watch_results(jid) @pool.watch("result#{jid}") @pool.ignore("default") @pool.ignore("job") end |