breeder 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.4
@@ -2,15 +2,16 @@ module Breeder
2
2
  module Watcher
3
3
  class Beanstalk < Base
4
4
 
5
- def initialize(client, tube, max_workers)
5
+ def initialize(client, tube, max_workers, progress_rate = 0.05)
6
6
  raise "max_workers must be at least 1" if max_workers < 1
7
7
  @client, @tube, @max_workers = client, tube, max_workers
8
8
  @last_check = nil
9
+ @progress_rate = progress_rate
9
10
  end
10
11
 
11
12
  def check(num_workers)
12
13
  num = jobs_ready
13
- if !!@last_check && num > @last_check && num_workers <= @max_workers
14
+ if !!@last_check && insufficient_progress?(num) && num_workers <= @max_workers
14
15
  decision = :spawn
15
16
  elsif !!@last_check && num < 0.5 * @last_check
16
17
  decision = :reap
@@ -21,6 +22,10 @@ module Breeder
21
22
  decision
22
23
  end
23
24
 
25
+ def insufficient_progress?(num_jobs)
26
+ num_jobs > (1 - @progress_rate) * @last_check
27
+ end
28
+
24
29
  def jobs_ready
25
30
  @client.stats_tube(@tube)['current-jobs-ready']
26
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: breeder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: