Module: Resque::Plugins::Director
- Includes:
- Remora
- Defined in:
- lib/resque/plugins/director.rb,
lib/resque/plugins/director/config.rb,
lib/resque/plugins/director/scaler.rb,
lib/resque/plugins/director/worker_tracker.rb
Defined Under Namespace
Modules: Config
Classes: Scaler, WorkerTracker
Instance Method Summary
collapse
Instance Method Details
#after_enqueue_scale_workers(*args) ⇒ Object
46
47
48
49
50
|
# File 'lib/resque/plugins/director.rb', line 46
def after_perform_direct_workers(*args)
set_queue
jobs_in_queue = Resque.size(@queue.to_s)
Scaler.scale_down_to_minimum if jobs_in_queue == 0
end
|
#after_pop_direct_workers(start_time = Time.now.utc) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/resque/plugins/director.rb', line 32
def after_pop_direct_workers(start_time=Time.now.utc)
return unless scaling_config_set?
set_queue
time_through_queue = Time.now.utc - start_time
jobs_in_queue = Resque.size(@queue.to_s)
if scale_up?(time_through_queue, jobs_in_queue)
Scaler.scale_up
elsif scale_down?(time_through_queue, jobs_in_queue)
Scaler.scale_down
end
end
|
#attach_remora ⇒ Object
6
7
8
|
# File 'lib/resque/plugins/director.rb', line 6
def attach_remora
{:created_at => Time.now.utc.to_i}
end
|
#direct(options = {}) ⇒ Object
16
17
18
19
|
# File 'lib/resque/plugins/director.rb', line 16
def direct(options={})
Config.setup(options)
Config.queue = options[:queue]
end
|
#on_failure_direct_workers(*args) ⇒ Object
52
53
54
55
56
|
# File 'lib/resque/plugins/director.rb', line 52
def on_failure_direct_workers(*args)
set_queue
jobs_in_queue = Resque.size(@queue.to_s)
Scaler.scale_down_to_minimum if jobs_in_queue == 0
end
|
#process_remora(queue, job) ⇒ Object
10
11
12
13
14
|
# File 'lib/resque/plugins/director.rb', line 10
def process_remora(queue, job)
timestamp = job['created_at']
start_time = timestamp.nil? ? Time.now.utc : Time.at(timestamp.to_i).utc
after_pop_direct_workers(start_time)
end
|