lib/resque/worker.rb in mongo-resque-1.17.1 vs lib/resque/worker.rb in mongo-resque-1.18.2
- old
+ new
@@ -290,11 +290,11 @@
# are we paused?
def paused?
@paused
end
-
+
# Stop processing jobs after the current one has completed (if we're
# currently running one).
def pause_processing
log "USR2 received; pausing job processing"
@paused = true
@@ -365,14 +365,13 @@
# Given a job, tells Mongo we're working on it. Useful for seeing
# what workers are doing and when.
def working_on(job)
job.worker = self
- data = #encode \
- { :queue => job.queue,
- :run_at => Time.now.to_s,
- :payload => job.payload}
+ data = { :queue => job.queue,
+ :run_at => Time.now.strftime("%Y/%m/%d %H:%M:%S %Z"),
+ :payload => job.payload }
mongo_workers.update({:worker => self.to_s}, { '$set' => { 'working_on' => data}}, :upsert => true)
end
# Called when we are done working - clears our `working_on` state
# and tells Mongo we processed a job.
@@ -461,15 +460,41 @@
# Returns Integer PID of running worker
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 [r]uby | 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