Class: Breeder::Watcher::Beanstalk
- Defined in:
- lib/breeder/watcher/beanstalk.rb
Instance Method Summary collapse
- #check(num_workers) ⇒ Object
-
#initialize(client, tube, max_workers, progress_rate = 0.05) ⇒ Beanstalk
constructor
A new instance of Beanstalk.
- #insufficient_progress?(num_jobs) ⇒ Boolean
- #jobs_ready ⇒ Object
Constructor Details
#initialize(client, tube, max_workers, progress_rate = 0.05) ⇒ Beanstalk
Returns a new instance of Beanstalk.
5 6 7 8 9 10 |
# File 'lib/breeder/watcher/beanstalk.rb', line 5 def initialize(client, tube, max_workers, progress_rate = 0.05) raise "max_workers must be at least 1" if max_workers < 1 @client, @tube, @max_workers = client, tube, max_workers @last_check = nil @progress_rate = progress_rate end |
Instance Method Details
#check(num_workers) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/breeder/watcher/beanstalk.rb', line 12 def check(num_workers) num = jobs_ready if !!@last_check && insufficient_progress?(num) && num_workers <= @max_workers decision = :spawn elsif !!@last_check && num < 0.5 * @last_check decision = :reap else decision = nil end @last_check = num decision end |
#insufficient_progress?(num_jobs) ⇒ Boolean
25 26 27 |
# File 'lib/breeder/watcher/beanstalk.rb', line 25 def insufficient_progress?(num_jobs) num_jobs > (1 - @progress_rate) * @last_check end |
#jobs_ready ⇒ Object
29 30 31 |
# File 'lib/breeder/watcher/beanstalk.rb', line 29 def jobs_ready @client.stats_tube(@tube)['current-jobs-ready'] end |