Basic Job Callbacks for Rails

80 views
Skip to first unread message

MaxCSV

unread,
Jun 29, 2020, 8:22:54 AM6/29/20
to delayed_job
I am using the most basic version of delayed_job in a Rails app. I have the max time allowed for a delayed_job set at 10 minutes. I would like to get the hooks/callbacks working so I can do something after a job stop executing at the 10 minute mark.

I have this set in my rails app:
config.active_job.queue_adapter = :delayed_job

This is how I normally queue a job:
object.delay.object_action

The hook/callback example is for a named job but the basic getting started is not for a named job. Here is the example given to get the callbacks working:

class ParanoidNewsletterJob < NewsletterJob
  def enqueue(job)
    record_stat 'newsletter_job/enqueue'
  end

  def perform
    emails.each { |e| NewsletterMailer.deliver_text_to_email(text, e) }
  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)
    Airbrake.notify(exception)
  end

  def failure(job)
    page_sysadmin_in_the_middle_of_the_night
  end
end

I would love to get the after or error hooks/callbacks to fire.

Where do I put these callbacks in my Rails app to have them fire for the basic delayed_job setup? If I should be using ActiveJob callbacks where do you put those callbacks given delayed_job is being used?
Reply all
Reply to author
Forward
Message has been deleted
0 new messages