Class: Delayed::Workless::Scaler::Base
- Inherits:
-
Object
- Object
- Delayed::Workless::Scaler::Base
show all
- Defined in:
- lib/workless/scalers/base.rb
Class Method Summary
collapse
Class Method Details
.calculate_num_workers(up = false) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/workless/scalers/base.rb', line 24
def self.calculate_num_workers up=false
num_jobs = self.jobs.count
@@scale_info ||= {
0 => 0,
100 => 1,
500 => 2,
1000 => 3
}
scale_key = nil
if up
scale_key = @@scale_info.keys.select{|v| v > num_jobs }.first
scale_key ||= @@scale_info.keys.last
else
scale_key = @@scale_info.keys.select{|v| v > num_jobs }.first
scale_key ||= @@scale_info.keys.last
scale_key = 0 if num_jobs == 0 end
if scale_key.nil?
return 0
else
return @@scale_info[scale_key]
end
end
|
.jobs ⇒ Object
8
9
10
|
# File 'lib/workless/scalers/base.rb', line 8
def self.jobs
Delayed::Job.where(:failed_at => nil)
end
|
.num_workers_cache ⇒ Object
16
17
18
|
# File 'lib/workless/scalers/base.rb', line 16
def self.num_workers_cache
Rails.cache.read("WORKLESS_NUM_WORKERS") || 0
end
|
.num_workers_cache=(num) ⇒ Object
20
21
22
|
# File 'lib/workless/scalers/base.rb', line 20
def self.num_workers_cache= num
Rails.cache.write("WORKLESS_NUM_WORKERS", num)
end
|
.scale_info=(info) ⇒ Object
12
13
14
|
# File 'lib/workless/scalers/base.rb', line 12
def self.scale_info= info
@@scale_info = info
end
|