Skip to content

Commit

Permalink
Update docs on hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Sep 6, 2010
1 parent a7751a8 commit 129a5d5
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions README.textile
Expand Up @@ -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
Expand Down

0 comments on commit 129a5d5

Please sign in to comment.