1
1
Resque Plugins
2
2
==============
3
3
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
+
6
45
7
46
Job Hooks
8
47
---------
9
48
10
49
Plugins can utilize job hooks to provide additional behavior. A job
11
50
hook is a method name in the following format:
12
51
13
- HOOK_IDENTIFIER
52
+ HOOKNAME_IDENTIFIER
14
53
15
54
For example, a ` before_perform ` hook which adds locking may be defined
16
55
like this:
@@ -26,8 +65,9 @@ method is called.
26
65
The available hooks are:
27
66
28
67
* ` 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.
31
71
32
72
* ` after_perform ` : Called with the job args after it performs. Uncaught
33
73
exceptions will propagate up to the ` Resque::Failure ` backend.
0 commit comments