Class: Resque::Pool::Killer
- Inherits:
-
Object
- Object
- Resque::Pool::Killer
show all
- Includes:
- Logging
- Defined in:
- lib/resque/pool/killer.rb
Constant Summary
collapse
- GRACEFUL_SHUTDOWN_SIGNAL =
:INT
- RESQUE_POOL_PIDS =
/
^\s*(\d+) # PID digits, optional leading spaces
\s+ # column divider
#{Regexp.escape(PROCLINE_PREFIX)} # exact match at start of command
/x
Constants included
from Logging
Logging::PROCLINE_PREFIX
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Logging
#app, #log, #log_worker, #procline, reopen_logs!
Class Method Details
.run ⇒ Object
8
9
10
|
# File 'lib/resque/pool/killer.rb', line 8
def self.run
new.run
end
|
Instance Method Details
#all_resque_pool_processes ⇒ Object
23
24
25
26
27
|
# File 'lib/resque/pool/killer.rb', line 23
def all_resque_pool_processes
out = `ps -e -o pid= -o command= 2>&1`
raise "Unable to identify other pools: #{out}" unless $?.success?
parse_pids_from_output out
end
|
#parse_pids_from_output(output) ⇒ Object
35
36
37
|
# File 'lib/resque/pool/killer.rb', line 35
def parse_pids_from_output(output)
output.scan(RESQUE_POOL_PIDS).flatten.map(&:to_i)
end
|
#run ⇒ Object
12
13
14
15
16
17
18
19
20
|
# File 'lib/resque/pool/killer.rb', line 12
def run
my_pid = Process.pid
pool_pids = all_resque_pool_processes
pids_to_kill = pool_pids.reject{|pid| pid == my_pid}
pids_to_kill.each do |pid|
log "Pool (#{my_pid}) in kill-others mode: killing pool with pid (#{pid})"
Process.kill(GRACEFUL_SHUTDOWN_SIGNAL, pid)
end
end
|