Skip to content

Commit

Permalink
Add an example of using modules for defining hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
merwan authored Jul 27, 2016
1 parent 1ff6f21 commit 0f381f0
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion HOOKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 0f381f0

Please sign in to comment.