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 =
|
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
|
-
|
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
|
-
|
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
|