Permalink
Browse files

added Worker#pid method

  • Loading branch information...
1 parent a4b19d4 commit c181644283512f879f4ba26ec5c5686b23ad7861 @morgoth morgoth committed with defunkt Dec 15, 2010
Showing with 10 additions and 1 deletion.
  1. +6 −1 lib/resque/worker.rb
  2. +4 −0 test/worker_test.rb
View
@@ -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
@@ -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

0 comments on commit c181644

Please sign in to comment.