Skip to content

Commit 6641828

Browse files
Andy Delcambresteveklabnik
authored andcommitted
Add the worker as a parameter to the before_first_fork hook.
1 parent afaa497 commit 6641828

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/resque/worker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def startup
255255
enable_gc_optimizations
256256
register_signal_handlers
257257
prune_dead_workers
258-
run_hook :before_first_fork
258+
run_hook :before_first_fork, self
259259
register_worker
260260

261261
# Fix buffering so we can `rake resque:work > resque.log` and

test/worker_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,16 @@ def self.perform
416416
# assert_equal 1, $BEFORE_FORK_CALLED
417417
end
418418

419+
it "Passes the worker to the before_first_fork hook" do
420+
$BEFORE_FORK_WORKER = nil
421+
Resque.before_first_fork = Proc.new { |w| $BEFORE_FORK_WORKER = w.id }
422+
workerA = Resque::Worker.new(:jobs)
423+
424+
Resque::Job.create(:jobs, SomeJob, 20, '/tmp')
425+
workerA.work(0)
426+
assert_equal workerA.id, $BEFORE_FORK_WORKER
427+
end
428+
419429
it "Will call a before_fork hook before forking" do
420430
$BEFORE_FORK_CALLED = false
421431
Resque.before_fork = Proc.new { $BEFORE_FORK_CALLED = true }

0 commit comments

Comments
 (0)