title: Configuring Exception Notification with Delayed Jobs in Rails 4
body: <p>I can't get the Exception Notification gem to notify me when a Delayed Job fails.  I can have jobs fail, but no notification is going out.  Anyone else figured this out?</p>
  
  <p>I'm using:</p>
  
  <pre><code>delayed_job_active_record (4.0.0)
  exception_notification (4.0.0)
  </code></pre>
  
  <p>And have the following in my initializers/delayed_jobs_config:</p>
  
  <pre><code># Chain delayed job's handle_failed_job method to do exception notification
  Delayed::Worker.class_eval do
    def handle_failed_job_with_notification(job, error)
      handle_failed_job_without_notification(job, error)
      # only actually send mail in production
      if Rails.env.production?
        # rescue if ExceptionNotifier fails for some reason
        begin
          ExceptionNotifier::Notifier.background_exception_notification(error)
        rescue Exception =&gt; e
          Rails.logger.error "ExceptionNotifier failed: #{e.class.name}: #{e.message}"
          e.backtrace.each do |f|
            Rails.logger.error "  #{f}"
          end
          Rails.logger.flush
        end
      end
    end
    alias_method_chain :handle_failed_job, :notification
  end
  </code></pre>