Skip to content

Commit

Permalink
Make Delayed::Job.worker_name compatible with daemonizing. Display th…
Browse files Browse the repository at this point in the history
…e correct pid.
  • Loading branch information
David Genord II authored and bkeepers committed Oct 16, 2009
1 parent cbb8bb0 commit 15ec587
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/delayed/job.rb
Expand Up @@ -24,8 +24,24 @@ class Job < ActiveRecord::Base
# Every worker has a unique name which by default is the pid of the process.
# There are some advantages to overriding this with something which survives worker retarts:
# Workers can safely resume working on tasks which are locked by themselves. The worker will assume that it crashed before.
cattr_accessor :worker_name
self.worker_name = "host:#{Socket.gethostname} pid:#{Process.pid}" rescue "pid:#{Process.pid}"
@@worker_name = nil

def self.worker_name
return @@worker_name unless @@worker_name.nil?
"host:#{Socket.gethostname} pid:#{Process.pid}" rescue "pid:#{Process.pid}"
end

def self.worker_name=(val)
@@worker_name = val
end

def worker_name
self.class.worker_name
end

def worker_name=(val)
@@worker_name = val
end

NextTaskSQL = '(run_at <= ? AND (locked_at IS NULL OR locked_at < ?) OR (locked_by = ?)) AND failed_at IS NULL'
NextTaskOrder = 'priority DESC, run_at ASC'
Expand Down

0 comments on commit 15ec587

Please sign in to comment.