将此模块包含在要延迟的类中:
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
Job name: <%= @job.name %>
Job: <%= raw @job.inspect %>
* Process: <%= raw $$ %>
* Server : <%= raw `hostname -s`.chomp %>