Skip to content

Commit 124be1b

Browse files
committed
Worker Hooks goes into PLUGINS.md
1 parent d566da1 commit 124be1b

File tree

2 files changed

+52
-35
lines changed

2 files changed

+52
-35
lines changed

PLUGINS.md

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,55 @@
11
Resque Plugins
22
==============
33

4-
Resque encourages plugin development. In most cases, customize your
5-
environment with a plugin rather than adding to the core.
4+
Resque encourages plugin development. For a list of available plugins
5+
see <http://wiki.github.com/defunkt/resque/plugins>
6+
7+
In most cases you can customize your environment with a plugin rather
8+
than adding to Resque itself.
9+
10+
11+
Worker Hooks
12+
------------
13+
14+
If you wish to have a Proc called before the worker forks for the
15+
first time, you can add it in the initializer like so:
16+
17+
Resque.before_first_fork do
18+
puts "Call me once before the worker forks the first time"
19+
end
20+
21+
You can also run a hook before _every_ fork:
22+
23+
Resque.before_fork do |job|
24+
puts "Call me before the worker forks"
25+
end
26+
27+
The `before_fork` hook will be run in the **parent** process. So, be
28+
careful - any changes you make will be permanent for the lifespan of
29+
the worker.
30+
31+
And after forking:
32+
33+
Resque.after_fork do |job|
34+
puts "Call me after the worker forks"
35+
end
36+
37+
The `after_fork` hook will be run in the child process and is passed
38+
the current job. Any changes you make, therefor, will only live as
39+
long as the job currently being processes.
40+
41+
All hooks can also be set using a setter, e.g.
42+
43+
Resque.after_fork = proc { puts "called" }
44+
645

746
Job Hooks
847
---------
948

1049
Plugins can utilize job hooks to provide additional behavior. A job
1150
hook is a method name in the following format:
1251

13-
HOOK_IDENTIFIER
52+
HOOKNAME_IDENTIFIER
1453

1554
For example, a `before_perform` hook which adds locking may be defined
1655
like this:
@@ -26,8 +65,9 @@ method is called.
2665
The available hooks are:
2766

2867
* `before_perform`: Called with the job args before perform. If it raises
29-
Resque::Job::DontPerform, the job is aborted. If other exceptions are
30-
raised, they will be propagated up the the `Resque::Failure` backend.
68+
`Resque::Job::DontPerform`, the job is aborted. If other exceptions
69+
are raised, they will be propagated up the the `Resque::Failure`
70+
backend.
3171

3272
* `after_perform`: Called with the job args after it performs. Uncaught
3373
exceptions will propagate up to the `Resque::Failure` backend.

README.markdown

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -653,39 +653,16 @@ this way we can tell our Sinatra app about the config file:
653653

654654
Now everyone is on the same page.
655655

656-
Worker Hooks
657-
------------
658-
659-
If you wish to have a Proc called before the worker forks for the
660-
first time, you can add it in the initializer like so:
661-
662-
Resque.before_first_fork do
663-
puts "Call me once before the worker forks the first time"
664-
end
665-
666-
You can also run a hook before _every_ fork:
667-
668-
Resque.before_fork do |job|
669-
puts "Call me before the worker forks"
670-
end
671-
672-
The `before_fork` hook will be run in the **parent** process. So, be
673-
careful - any changes you make will be permanent for the lifespan of
674-
the worker.
675-
676-
And after forking:
677656

678-
Resque.after_fork do |job|
679-
puts "Call me after the worker forks"
680-
end
681-
682-
The `after_fork` hook will be run in the child process and is passed
683-
the current job. Any changes you make, therefor, will only live as
684-
long as the job currently being processes.
657+
Plugins
658+
-------
685659

686-
All hooks can also be set using a setter, e.g.
660+
For a list of available plugins see
661+
<http://wiki.github.com/defunkt/resque/plugins>.
687662

688-
Resque.after_fork = proc { puts "called" }
663+
If you'd like to write your own plugin, or want to see what hooks are
664+
available (such as `Resque.after_fork`), see
665+
[PLUGINS.md](http://github.com/defunkt/resque/blob/master/PLUGINS.md).
689666

690667

691668
Namespaces

0 commit comments

Comments
 (0)