Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added Worker#pid method

  • Loading branch information...
commit c181644283512f879f4ba26ec5c5686b23ad7861 1 parent a4b19d4
@morgoth morgoth authored defunkt committed
Showing with 10 additions and 1 deletion.
  1. +6 −1 lib/resque/worker.rb
  2. +4 −0 test/worker_test.rb
View
7 lib/resque/worker.rb
@@ -453,7 +453,7 @@ def inspect
# The string representation is the same as the id for this worker
# instance. Can be used with `Worker.find`.
def to_s
- @to_s ||= "#{hostname}:#{Process.pid}:#{@queues.join(',')}"
+ @to_s ||= "#{hostname}:#{pid}:#{@queues.join(',')}"
end
alias_method :id, :to_s
@@ -462,6 +462,11 @@ def hostname
@hostname ||= `hostname`.chomp
end
+ # Returns PID of running worker
+ def pid
+ @pid ||= Process.pid
+ end
+
# Returns an array of string pids of all the other workers on this
# machine. Useful when pruning dead workers on startup.
def worker_pids
View
4 test/worker_test.rb
@@ -312,4 +312,8 @@
workerA.work(0)
assert $AFTER_FORK_CALLED
end
+
+ test "returns PID of running process" do
+ assert_equal Process.pid, @worker.pid
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.