From 0f381f080be6986d92e654a5ca80d0789fa0f8fa Mon Sep 17 00:00:00 2001 From: Merouane Atig Date: Wed, 27 Jul 2016 13:42:47 +0200 Subject: [PATCH] Add an example of using modules for defining hooks --- HOOKS.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/HOOKS.md b/HOOKS.md index b68f377..1e06dee 100644 --- a/HOOKS.md +++ b/HOOKS.md @@ -56,7 +56,31 @@ class SomeJob end ``` -You can also setup modules to create compose-able and reusable hooks for your jobs. +You can also setup modules to create compose-able and reusable hooks for your jobs. For example: + +```ruby +module LoggedJob + def before_perform_log_job(*args) + Logger.info "About to perform #{self} with #{args.inspect}" + end +end + +module BuriedJob + def on_failure_bury(e, *args) + Logger.info "Performing #{self} caused an exception (#{e}). Retrying..." + self.bury + end +end + +class MyJob + extend LoggedJob + extend BuriedJob + + def self.perform(*args) + # ... + end +end +``` ## Worker Hooks