Skip to content

Commit 5765fe1

Browse files
christiannelsondefunkt
authored andcommitted
Write out worker pid to PIDFILE if specified.
1 parent b51802d commit 5765fe1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

README.markdown

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,13 @@ variable.
235235

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

238+
### Process IDs (PIDs)
239+
240+
There are scenarios where it's helpful to record the PID of a resque
241+
worker process. Use the PIDFILE option for easy access to the PID:
242+
243+
$ PIDFILE=./resque.pid QUEUE=file_serve rake environment resque:work
244+
238245

239246
### Priorities and Queue Lists
240247

lib/resque/tasks.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
task :work => :setup do
99
require 'resque'
1010

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

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

21+
if ENV['PIDFILE']
22+
File.open(ENV['PIDFILE'], 'w') { |f| f << Process.pid.to_s }
23+
end
24+
2225
worker.log "Starting worker #{worker}"
2326

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

0 commit comments

Comments
 (0)