Skip to content

Commit 0bc0173

Browse files
tarcieristeveklabnik
authored andcommitted
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. Conflicts: test/worker_test.rb
1 parent 1f5a5ae commit 0bc0173

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

lib/resque/worker.rb

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

test/worker_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,14 +483,15 @@ def self.perform
483483
end
484484

485485
it "Will call an after_fork hook after forking" do
486+
Resque.redis.flushall
486487
$AFTER_FORK_CALLED = false
487488
Resque.after_fork = Proc.new { $AFTER_FORK_CALLED = true }
488489
workerA = Resque::Worker.new(:jobs)
489490

490491
assert !$AFTER_FORK_CALLED
491492
Resque::Job.create(:jobs, SomeJob, 20, '/tmp')
492493
workerA.work(0)
493-
assert $AFTER_FORK_CALLED
494+
assert $AFTER_FORK_CALLED == workerA.will_fork?
494495
end
495496

496497
it "Will not call an after_fork hook when the worker can't fork" do

0 commit comments

Comments
 (0)