Skip to content

Commit

Permalink
Add solaris_worker_pids
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Hawker authored and defunkt committed Aug 18, 2011
1 parent e947af0 commit 8c9be28
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions lib/resque/worker.rb
Expand Up @@ -302,7 +302,7 @@ def kill_child
def paused?
@paused
end

# Stop processing jobs after the current one has completed (if we're
# currently running one).
def pause_processing
Expand Down Expand Up @@ -473,14 +473,40 @@ def pid
@pid ||= to_s.split(":")[1].to_i
end

# Returns an array of string pids of all the other workers on this
# Returns an Array of string pids of all the other workers on this
# machine. Useful when pruning dead workers on startup.
def worker_pids
if RUBY_PLATFORM =~ /solaris/
solaris_worker_pids
else
linux_worker_pids
end
end

# Find Resque worker pids on Linux and OS X.
#
# Returns an Array of string pids of all the other workers on this
# machine. Useful when pruning dead workers on startup.
def linux_worker_pids
`ps -A -o pid,command | grep [r]esque | grep -v "resque-web"`.split("\n").map do |line|
line.split(' ')[0]
end
end

# Find Resque worker pids on Solaris.
#
# Returns an Array of string pids of all the other workers on this
# machine. Useful when pruning dead workers on startup.
def solaris_worker_pids
`ps -A -o pid,comm | grep ruby | grep -v grep | grep -v "resque-web"`.split("\n").map do |line|
real_pid = line.split(' ')[0]
pargs_command = `pargs -a #{real_pid} 2>/dev/null | grep [r]esque | grep -v "resque-web"`
if pargs_command.split(':')[1] == " resque-#{Resque::Version}"
real_pid
end
end.compact
end

# Given a string, sets the procline ($0) and logs.
# Procline is always in the format of:
# resque-VERSION: STRING
Expand Down

0 comments on commit 8c9be28

Please sign in to comment.