4

Есть ли особенность exception_notification-gem для delayed_job? Предпочтительно, что это работает с REE-1.8.7 и Rails 2.3.10.exception_notification для delayed_job

+0

переключился на Resque =) – razenha

+0

При использовании Resque, [этот маленький драгоценный камень] (https://github.com/akshayrawat/resque_exception_notification) сообщает об исключениях через exception_notification. –

ответ

3

Я сделал что-то подобное в прошлом для запаздывающих задач работы грабель:

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 

торцевого

2

Включите этот модуль в классах, которые должны быть отсрочено:


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 

и создать шаблон для уведомления в приложении/views/exception_notifier/_delayed_job.text.erb:


Job name: <%= @job.name %> 
Job: <%= raw @job.inspect %> 

* Process: <%= raw $$ %> 
* Server : <%= raw `hostname -s`.chomp %> 
Смежные вопросы