Skip to content

Commit 1a48dd2

Browse files
committed
Don't run the :after_fork hook if the worker hasn't actually forked.
1 parent 86b6b83 commit 1a48dd2

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/resque/worker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def process(job = nil, &block)
183183
# Processes a given job in the child.
184184
def perform(job)
185185
begin
186-
run_hook :after_fork, job
186+
run_hook :after_fork, job unless @cant_fork
187187
job.perform
188188
rescue Object => e
189189
log "#{job.inspect} failed: #{e.inspect}"

test/worker_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,19 @@ def self.perform
421421
assert $AFTER_FORK_CALLED
422422
end
423423

424+
test "Will not call an after_fork hook when the worker can't fork" do
425+
Resque.redis.flushall
426+
$AFTER_FORK_CALLED = false
427+
Resque.after_fork = Proc.new { $AFTER_FORK_CALLED = true }
428+
workerA = Resque::Worker.new(:jobs)
429+
workerA.cant_fork = true
430+
431+
assert !$AFTER_FORK_CALLED
432+
Resque::Job.create(:jobs, SomeJob, 20, '/tmp')
433+
workerA.work(0)
434+
assert !$AFTER_FORK_CALLED
435+
end
436+
424437
test "returns PID of running process" do
425438
assert_equal @worker.to_s.split(":")[1].to_i, @worker.pid
426439
end

0 commit comments

Comments
 (0)