rcarvalho-workless 1.0.2.13 → 1.0.2.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,7 +21,7 @@ module Delayed
21
21
  Rails.cache.write("WORKLESS_NUM_WORKERS", num)
22
22
  end
23
23
 
24
- def self.calculate_num_workers
24
+ def self.calculate_num_workers up=false
25
25
  num_jobs = self.jobs.count
26
26
  @@scale_info ||= {
27
27
  0 => 0,
@@ -29,7 +29,15 @@ module Delayed
29
29
  500 => 2,
30
30
  1000 => 3
31
31
  }
32
- scale_key = @@scale_info.keys.reverse.select{|v| v <= num_jobs }.first
32
+ scale_key = nil
33
+ if up
34
+ scale_key = @@scale_info.keys.select{|v| v > num_jobs }.first
35
+ scale_key ||= @@scale_info.keys.last
36
+ else
37
+ scale_key = @@scale_info.keys.select{|v| v > num_jobs }.first
38
+ scale_key = 0 if num_jobs == 0 # special case
39
+ end
40
+
33
41
  if scale_key.nil?
34
42
  return 0
35
43
  else
@@ -10,20 +10,25 @@ module Delayed
10
10
 
11
11
  def self.up
12
12
  nw = self.calculate_num_workers
13
- client.set_workers(ENV['APP_NAME'], nw) if nw
13
+ if nw
14
+ if self.num_workers_cache != nw
15
+ self.num_workers_cache = nw
16
+ client.set_workers(ENV['APP_NAME'], nw)
17
+ end
18
+ end
14
19
  rescue
15
20
  end
16
21
 
17
22
  def self.down
18
23
  nw = self.calculate_num_workers
19
- client.set_workers(ENV['APP_NAME'], nw) unless self.workers == 0 or self.jobs.count > 0
24
+ if nw
25
+ if self.num_workers_cache != nw
26
+ self.num_workers_cache = nw
27
+ client.set_workers(ENV['APP_NAME'], nw)
28
+ end
29
+ end
20
30
  rescue
21
31
  end
22
-
23
- def self.workers
24
- client.info(ENV['APP_NAME'])[:workers].to_i
25
- end
26
-
27
32
  end
28
33
 
29
34
  end
@@ -29,11 +29,6 @@ module Delayed
29
29
  end
30
30
  rescue
31
31
  end
32
-
33
- def self.workers
34
- self.num_workers_cache
35
- end
36
-
37
32
  end
38
33
 
39
34
  end
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 1
7
7
  - 0
8
8
  - 2
9
- - 13
10
- version: 1.0.2.13
9
+ - 14
10
+ version: 1.0.2.14
11
11
  platform: ruby
12
12
  authors:
13
13
  - lostboy