rcarvalho-workless 1.0.2.9 → 1.0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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 @@current_num_workers != nw
16
- @@current_num_workers = nw
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 @@current_num_workers != nw
28
- @@current_num_workers = nw
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
- @@current_num_workers ||= 0
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
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 1
7
7
  - 0
8
8
  - 2
9
- - 9
10
- version: 1.0.2.9
9
+ - 10
10
+ version: 1.0.2.10
11
11
  platform: ruby
12
12
  authors:
13
13
  - lostboy