rcarvalho-workless 1.0.2.9 → 1.0.2.10
Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,14 @@ module Delayed
|
|
8
8
|
def self.jobs
|
9
9
|
Delayed::Job.all(:conditions => { :failed_at => nil })
|
10
10
|
end
|
11
|
+
|
12
|
+
def self.num_workers_cache
|
13
|
+
Rails.cache.read("WORKLESS_NUM_WORKERS") || 0
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.num_workers_cache= num
|
17
|
+
Rails.cache.write("WORKLESS_NUM_WORKERS", num)
|
18
|
+
end
|
11
19
|
|
12
20
|
def self.calculate_num_workers
|
13
21
|
num_workers = self.workers
|
@@ -9,11 +9,10 @@ module Delayed
|
|
9
9
|
extend Delayed::Workless::Scaler::HerokuClient
|
10
10
|
|
11
11
|
def self.up
|
12
|
-
@@current_num_workers ||= 0
|
13
12
|
nw = self.calculate_num_workers
|
14
13
|
if nw
|
15
|
-
if
|
16
|
-
|
14
|
+
if self.num_workers_cache != nw
|
15
|
+
self.num_workers_cache = nw
|
17
16
|
client.ps_scale(ENV['APP_NAME'], :type => 'worker', :qty => @@current_num_workers)
|
18
17
|
end
|
19
18
|
end
|
@@ -21,11 +20,10 @@ module Delayed
|
|
21
20
|
end
|
22
21
|
|
23
22
|
def self.down
|
24
|
-
@@current_num_workers ||= 0
|
25
23
|
nw = self.calculate_num_workers
|
26
24
|
if nw
|
27
|
-
if
|
28
|
-
|
25
|
+
if self.num_workers_cache != nw
|
26
|
+
self.num_workers_cache = nw
|
29
27
|
client.ps_scale(ENV['APP_NAME'], :type => 'worker', :qty => nw)
|
30
28
|
end
|
31
29
|
end
|
@@ -33,8 +31,7 @@ module Delayed
|
|
33
31
|
end
|
34
32
|
|
35
33
|
def self.workers
|
36
|
-
|
37
|
-
@@current_num_workers || client.ps(ENV['APP_NAME']).count { |p| p["process"] =~ /worker\.\d?/ }
|
34
|
+
self.num_workers_cache
|
38
35
|
end
|
39
36
|
|
40
37
|
end
|