exception_notification for delayed_job

后端 未结 2 1922
情深已故
情深已故 2021-01-01 04:41

Is there a exception_notification-like gem for delayed_job? Preferably that works with REE-1.8.7 and Rails 2.3.10.

2条回答
  •  无人及你
    2021-01-01 05:20

    Include this module in classes which are to be delayed:

    
    require 'exception_notifier'
    module Delayed
      module ExceptionNotifier
        # Send error via exception notifier
        def error(job, e)
          env = {}
          env['exception_notifier.options'] = {
            :sections => %w(backtrace delayed_job),
            :email_prefix => '[Delayed Job ERROR] ',
            :exception_recipients => %w(some@email.com),
            :sender_address => %(other@email.com)
          }
          env['exception_notifier.exception_data'] = {:job => job}
          ::ExceptionNotifier::Notifier.exception_notification(env, e).deliver
        end
      end
    end
    

    and create a template for the notification in app/views/exception_notifier/_delayed_job.text.erb:

    
    Job name: <%= @job.name %>
    Job: <%= raw @job.inspect %>
    
    * Process: <%= raw $$ %>
    * Server : <%= raw `hostname -s`.chomp %>
    

提交回复
热议问题