Skip to content

Commit 60b157d

Browse files
committed
Daemonizes when BACKGROUND environment var is set
1 parent 78273c2 commit 60b157d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/resque/tasks.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
abort "set QUEUE env var, e.g. $ QUEUE=critical,high rake resque:work"
1919
end
2020

21+
if ENV['BACKGROUND']
22+
Process.daemon(true)
23+
end
24+
2125
if ENV['PIDFILE']
2226
File.open(ENV['PIDFILE'], 'w') { |f| f << worker.pid }
2327
end

lib/resque/worker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ def hostname
470470

471471
# Returns Integer PID of running worker
472472
def pid
473-
@pid ||= to_s.split(":")[1].to_i
473+
Process.pid
474474
end
475475

476476
# Returns an Array of string pids of all the other workers on this

0 commit comments

Comments
 (0)