Class: Resque::Plugins::Director::WorkerTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/resque/plugins/director/worker_tracker.rb

Class Method Summary collapse

Class Method Details

.total_for_requirementsObject



7
8
9
10
11
12
13
# File 'lib/resque/plugins/director/worker_tracker.rb', line 7

def total_for_requirements
  start_number = workers_to_start
  stop_number = workers_to_stop
  return start_number if start_number > 0 
  return stop_number if stop_number < 0 
  0
end

.total_to_add(number_to_start) ⇒ Object



20
21
22
23
24
25
# File 'lib/resque/plugins/director/worker_tracker.rb', line 20

def total_to_add(number_to_start)
  return number_to_start if Config.max_workers <= 0
  scale_limit = Config.max_workers - current_workers.size
  Config.log("WORKER MAX REACHED: wanted to start #{number_to_start} workers on queue:#{Config.queue}") if scale_limit <= 0
  number_to_start > scale_limit ? scale_limit : number_to_start
end

.total_to_go_to_minimumObject



15
16
17
18
# File 'lib/resque/plugins/director/worker_tracker.rb', line 15

def total_to_go_to_minimum
  to_minimum =  current_workers.size - Config.min_workers
  to_minimum > 0 ? to_minimum : 0
end

.total_to_remove(number_to_stop) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/resque/plugins/director/worker_tracker.rb', line 27

def total_to_remove(number_to_stop)
  min_workers = Config.min_workers <= 0 ? 1 : Config.min_workers
  scale_limit = current_workers.size - min_workers
  if scale_limit <= 0 && Config.min_workers > 0
    Config.log("WORKER MIN REACHED: wanted to stop #{number_to_stop} workers on queue:#{Config.queue}")
  end
  number_to_stop > scale_limit ? scale_limit : number_to_stop
end

.valid_worker_pidsObject



36
37
38
39
# File 'lib/resque/plugins/director/worker_tracker.rb', line 36

def valid_worker_pids
  valid_workers = current_workers.select{|w| w.hostname == `hostname`.chomp}
  valid_workers.map{|worker| worker.to_s.split(":")[1].to_i }
end