4
是否有一個delayed_job的exception_notification樣的寶石? 最好與REE-1.8.7和Rails 2.3.10工作。exception_notification爲delayed_job的
是否有一個delayed_job的exception_notification樣的寶石? 最好與REE-1.8.7和Rails 2.3.10工作。exception_notification爲delayed_job的
我做了這樣的事情在過去的延遲工作rake任務:
require 'action_mailer'
class ExceptionMailer < ActionMailer::Base
def setup_mail
@from = ExceptionNotifier.sender_address
@sent_on = Time.now
@content_type = "text/plain"
end
def exception_message(subject, message)
setup_mail
@subject = subject
@recipients = ExceptionNotifier.exception_recipients
@body = message
end
end
namespace :jobs do
desc "sync the local database with the remote CMS"
task(:sync_cms => :environment) do
Resort.sync_all!
result = Delayed::Job.work_off
unless result[1].zero?
ExceptionMailer.deliver_exception_message("[SYNC CMS] Error syncing CMS id: #{Delayed::Job.last.id}", Delayed::Job.last.last_error)
end
end
末
包含在該模塊中的類將被延遲:
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([email protected]),
:sender_address => %([email protected])
}
env['exception_notifier.exception_data'] = {:job => job}
::ExceptionNotifier::Notifier.exception_notification(env, e).deliver
end
end
end
並創建一個模板在app /視圖/ exception_notifier/_delayed_job.text.erb通知:
Job name: <%= @job.name %>
Job: <%= raw @job.inspect %>
* Process: <%= raw $$ %>
* Server : <%= raw `hostname -s`.chomp %>
切換到Resque =) – razenha 2011-06-16 18:08:48
當使用Resque,[這個小寶石](https://github.com/akshayrawat/resque_exception_notification)經由exception_notification報告異常。 – 2013-03-25 06:17:52