Permalink
Browse files

Update docs on hooks

  • Loading branch information...
1 parent a7751a8 commit 129a5d50d85e2e091d6d82e258291297d1c278e5 @bkeepers bkeepers committed Sep 6, 2010
Showing with 21 additions and 3 deletions.
  1. +21 −3 README.textile
View
@@ -108,15 +108,33 @@ end
Delayed::Job.enqueue NewsletterJob.new('lorem ipsum...', Customers.find(:all).collect(&:email))
</pre>
-You can also add an optional on_permanent_failure method which will run if the job has failed too many times to be retried:
+h2. Hooks
+
+You can define hooks on your job that will be called at different stages in the process:
<pre>
class ParanoidNewsletterJob < NewsletterJob
def perform
emails.each { |e| NewsletterMailer.deliver_text_to_email(text, e) }
- end
+ end
+
+ def before(job)
+ record_stat 'newsletter_job/start'
+ end
+
+ def after(job)
+ record_stat 'newsletter_job/after'
+ end
+
+ def success(job)
+ record_stat 'newsletter_job/success'
+ end
+
+ def error(job, exception)
+ notify_hoptoad(exception)
+ end
- def on_permanent_failure
+ def failure
page_sysadmin_in_the_middle_of_the_night
end
end

0 comments on commit 129a5d5

Please sign in to comment.