2

当延迟作业失败时,我无法让异常通知 gem 通知我。我可以让作业失败,但不会发出任何通知。还有人想出这个吗?

我正在使用:

delayed_job_active_record (4.0.0)
exception_notification (4.0.0)

在我的初始化程序/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
4

1 回答 1

3

从 exception_notification 4.0开始,有一种处理手动 notify 的新方法。尝试改变

ExceptionNotifier::Notifier.background_exception_notification(error)

为了

ExceptionNotifier.notify_exception(error)
于 2013-12-09T18:19:37.480 回答