Skip to content

Commit

Permalink
Worker Hooks goes into PLUGINS.md
Browse files Browse the repository at this point in the history
  • Loading branch information
defunkt committed Apr 1, 2010
1 parent d566da1 commit 124be1b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 35 deletions.
50 changes: 45 additions & 5 deletions PLUGINS.md
@@ -1,16 +1,55 @@
Resque Plugins
==============

Resque encourages plugin development. In most cases, customize your
environment with a plugin rather than adding to the core.
Resque encourages plugin development. For a list of available plugins
see <http://wiki.github.com/defunkt/resque/plugins>

In most cases you can customize your environment with a plugin rather
than adding to Resque itself.


Worker Hooks
------------

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

Resque.before_first_fork do
puts "Call me once before the worker forks the first time"
end

You can also run a hook before _every_ fork:

Resque.before_fork do |job|
puts "Call me before the worker forks"
end

The `before_fork` hook will be run in the **parent** process. So, be
careful - any changes you make will be permanent for the lifespan of
the worker.

And after forking:

Resque.after_fork do |job|
puts "Call me after the worker forks"
end

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

All hooks can also be set using a setter, e.g.

Resque.after_fork = proc { puts "called" }


Job Hooks
---------

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

HOOK_IDENTIFIER
HOOKNAME_IDENTIFIER

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

* `before_perform`: Called with the job args before perform. If it raises
Resque::Job::DontPerform, the job is aborted. If other exceptions are
raised, they will be propagated up the the `Resque::Failure` backend.
`Resque::Job::DontPerform`, the job is aborted. If other exceptions
are raised, they will be propagated up the the `Resque::Failure`
backend.

* `after_perform`: Called with the job args after it performs. Uncaught
exceptions will propagate up to the `Resque::Failure` backend.
Expand Down
37 changes: 7 additions & 30 deletions README.markdown
Expand Up @@ -653,39 +653,16 @@ this way we can tell our Sinatra app about the config file:

Now everyone is on the same page.

Worker Hooks
------------

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

Resque.before_first_fork do
puts "Call me once before the worker forks the first time"
end

You can also run a hook before _every_ fork:

Resque.before_fork do |job|
puts "Call me before the worker forks"
end

The `before_fork` hook will be run in the **parent** process. So, be
careful - any changes you make will be permanent for the lifespan of
the worker.

And after forking:

Resque.after_fork do |job|
puts "Call me after the worker forks"
end

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

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

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


Namespaces
Expand Down

0 comments on commit 124be1b

Please sign in to comment.