在Rails中配置具有延迟作业的异常通知4

时间:2013-09-13 03:20:10

标签: ruby-on-rails ruby-on-rails-4 delayed-job exception-notification

我无法获得Exception Notification gem,以便在延迟作业失败时通知我。我可以让工作失败,但没有通知。其他人都想出来了吗?

我正在使用:

delayed_job_active_record (4.0.0)
exception_notification (4.0.0)

在我的initializers / delayed_jobs_config中有以下内容:

# 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 => 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

1 个答案:

答案 0 :(得分:3)

自exception_notification 4.0 there's a new way to handle manual notify以来。尝试改变

ExceptionNotifier::Notifier.background_exception_notification(error)

代表

ExceptionNotifier.notify_exception(error)