Skip to content

Commit 8c9be28

Browse files
Dan Hawkerdefunkt
authored andcommitted
Add solaris_worker_pids
1 parent e947af0 commit 8c9be28

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

lib/resque/worker.rb

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def kill_child
302302
def paused?
303303
@paused
304304
end
305-
305+
306306
# Stop processing jobs after the current one has completed (if we're
307307
# currently running one).
308308
def pause_processing
@@ -473,14 +473,40 @@ def pid
473473
@pid ||= to_s.split(":")[1].to_i
474474
end
475475

476-
# Returns an array of string pids of all the other workers on this
476+
# Returns an Array of string pids of all the other workers on this
477477
# machine. Useful when pruning dead workers on startup.
478478
def worker_pids
479+
if RUBY_PLATFORM =~ /solaris/
480+
solaris_worker_pids
481+
else
482+
linux_worker_pids
483+
end
484+
end
485+
486+
# Find Resque worker pids on Linux and OS X.
487+
#
488+
# Returns an Array of string pids of all the other workers on this
489+
# machine. Useful when pruning dead workers on startup.
490+
def linux_worker_pids
479491
`ps -A -o pid,command | grep [r]esque | grep -v "resque-web"`.split("\n").map do |line|
480492
line.split(' ')[0]
481493
end
482494
end
483495

496+
# Find Resque worker pids on Solaris.
497+
#
498+
# Returns an Array of string pids of all the other workers on this
499+
# machine. Useful when pruning dead workers on startup.
500+
def solaris_worker_pids
501+
`ps -A -o pid,comm | grep ruby | grep -v grep | grep -v "resque-web"`.split("\n").map do |line|
502+
real_pid = line.split(' ')[0]
503+
pargs_command = `pargs -a #{real_pid} 2>/dev/null | grep [r]esque | grep -v "resque-web"`
504+
if pargs_command.split(':')[1] == " resque-#{Resque::Version}"
505+
real_pid
506+
end
507+
end.compact
508+
end
509+
484510
# Given a string, sets the procline ($0) and logs.
485511
# Procline is always in the format of:
486512
# resque-VERSION: STRING

0 commit comments

Comments
 (0)