Skip to content

Commit 6026def

Browse files
committed
before_first_fork / before_fork / after_fork docs
1 parent 5af6f86 commit 6026def

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

README.markdown

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,11 +648,32 @@ this way we can tell our Sinatra app about the config file:
648648

649649
Now everyone is on the same page.
650650

651-
If you wish to have a Proc called before the worker forks for the first time, you
652-
can add it in the initializer like so:
651+
If you wish to have a Proc called before the worker forks for the
652+
first time, you can add it in the initializer like so:
653653

654-
Resque.before_fork = Proc.new { puts "CALL ME ONCE BEFORE THE WORKER FORKS THE FIRST TIME" }
654+
Resque.before_first_fork do
655+
puts "CALL ME ONCE BEFORE THE WORKER FORKS THE FIRST TIME"
656+
end
657+
658+
You can also run a hook before _every_ fork:
659+
660+
Resque.before_fork do |job|
661+
puts "CALL ME ONCE BEFORE THE WORKER FORKS THE FIRST TIME"
662+
end
663+
664+
The `before_fork` hook will be run in the **parent** process. So, be
665+
careful - any changes you make will be permanent for the lifespan of
666+
the worker.
667+
668+
And after forking:
669+
670+
Resque.after_fork do |job|
671+
puts "CALL ME ONCE BEFORE THE WORKER FORKS THE FIRST TIME"
672+
end
655673

674+
The `after_fork` hook will be run in the child process and is passed
675+
the current job. Any changes you make, therefor, will only live as
676+
long as the job currently being processes.
656677

657678
Namespaces
658679
----------

0 commit comments

Comments
 (0)