Skip to content

Commit

Permalink
Write out worker pid to PIDFILE if specified.
Browse files Browse the repository at this point in the history
  • Loading branch information
christiannelson authored and defunkt committed Feb 4, 2011
1 parent b51802d commit 5765fe1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ variable.

$ VVERBOSE=1 QUEUE=file_serve rake environment resque:work

### Process IDs (PIDs)

There are scenarios where it's helpful to record the PID of a resque
worker process. Use the PIDFILE option for easy access to the PID:

$ PIDFILE=./resque.pid QUEUE=file_serve rake environment resque:work


### Priorities and Queue Lists

Expand Down
5 changes: 4 additions & 1 deletion lib/resque/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
task :work => :setup do
require 'resque'

worker = nil
queues = (ENV['QUEUES'] || ENV['QUEUE']).to_s.split(',')

begin
Expand All @@ -19,6 +18,10 @@
abort "set QUEUE env var, e.g. $ QUEUE=critical,high rake resque:work"
end

if ENV['PIDFILE']
File.open(ENV['PIDFILE'], 'w') { |f| f << Process.pid.to_s }
end

worker.log "Starting worker #{worker}"

worker.work(ENV['INTERVAL'] || 5) # interval, will block
Expand Down

0 comments on commit 5765fe1

Please sign in to comment.