Skip to content

Commit 4cab19d

Browse files
committed
Only call after_fork if will_fork? is true
This change provides consistent forking semantics across JRuby running in both 1.8 and 1.9 mode and resolves the current test failure.
1 parent 60f5365 commit 4cab19d

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
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 unless @cant_fork
186+
run_hook :after_fork, job if will_fork?
187187
job.perform
188188
rescue Object => e
189189
log "#{job.inspect} failed: #{e.inspect}"

test/worker_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def self.perform
409409
end
410410
end
411411

412-
test "Will call an after_fork hook after forking" do
412+
test "Will call an after_fork hook if we're forking" do
413413
Resque.redis.flushall
414414
$AFTER_FORK_CALLED = false
415415
Resque.after_fork = Proc.new { $AFTER_FORK_CALLED = true }
@@ -418,7 +418,7 @@ def self.perform
418418
assert !$AFTER_FORK_CALLED
419419
Resque::Job.create(:jobs, SomeJob, 20, '/tmp')
420420
workerA.work(0)
421-
assert $AFTER_FORK_CALLED
421+
assert $AFTER_FORK_CALLED == workerA.will_fork?
422422
end
423423

424424
test "Will not call an after_fork hook when the worker can't fork" do

0 commit comments

Comments
 (0)