From 124be1b73b699ed23b9f167203cc34b82008d05b Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Wed, 31 Mar 2010 20:35:40 -0700 Subject: [PATCH] Worker Hooks goes into PLUGINS.md --- PLUGINS.md | 50 ++++++++++++++++++++++++++++++++++++++++++++----- README.markdown | 37 +++++++----------------------------- 2 files changed, 52 insertions(+), 35 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index d0aa97f3d..04b1d5d2a 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -1,8 +1,47 @@ 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 + +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 --------- @@ -10,7 +49,7 @@ 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: @@ -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. diff --git a/README.markdown b/README.markdown index 7ae0c07ae..f3b4072c5 100644 --- a/README.markdown +++ b/README.markdown @@ -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 +. - 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