rcarvalho-workless 1.0.2.11 → 1.0.2.12

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.
Files changed (2) hide show
  1. data/lib/workless/scalers/base.rb +14 -11
  2. metadata +2 -2
@@ -9,6 +9,10 @@ module Delayed
9
9
  Delayed::Job.all(:conditions => { :failed_at => nil })
10
10
  end
11
11
 
12
+ def self.scale_info= info
13
+ @@scale_info = info
14
+ end
15
+
12
16
  def self.num_workers_cache
13
17
  Rails.cache.read("WORKLESS_NUM_WORKERS") || 0
14
18
  end
@@ -18,19 +22,18 @@ module Delayed
18
22
  end
19
23
 
20
24
  def self.calculate_num_workers
21
- num_workers = self.workers
22
25
  if num_workers.class == Fixnum
23
- job_count = self.jobs.count
24
- if job_count > 500
25
- return 4 unless num_workers > 3
26
- elsif job_count > 200
27
- return 3 unless num_workers > 2
28
- elsif job_count > 50
29
- return 2 unless num_workers > 1
30
- elsif job_count > 0
31
- return 1 unless num_workers > 0
32
- else
26
+ @@scale_info ||= {
27
+ 0 => 1,
28
+ 100 => 2,
29
+ 500 => 3,
30
+ 1000 => 4
31
+ }
32
+ scale_key = @@scale_info.keys.reverse.select{|v| v < num_workers }.first
33
+ if scale_key.nil?
33
34
  return 0
35
+ else
36
+ return @@scale_info[scale_key]
34
37
  end
35
38
  end
36
39
  end
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 1
7
7
  - 0
8
8
  - 2
9
- - 11
10
- version: 1.0.2.11
9
+ - 12
10
+ version: 1.0.2.12
11
11
  platform: ruby
12
12
  authors:
13
13
  - lostboy