diff --git a/config/initializers/delayed_job_config.rb b/config/initializers/delayed_job_config.rb index 6aa3e45..f7da459 100644 --- a/config/initializers/delayed_job_config.rb +++ b/config/initializers/delayed_job_config.rb @@ -23,3 +23,13 @@ end # end # alias_method_chain :handle_failed_job, :loggin #end + +# 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 + ExceptionNotifier.notify_exception error, exception_recipients: NOOSFERO_CONF['exception_recipients'], + data: {job: job, handler: job.handler} rescue nil + end + alias_method_chain :handle_failed_job, :notification +end diff --git a/vendor/plugins/delayed_job/lib/delayed/backend/base.rb b/vendor/plugins/delayed_job/lib/delayed/backend/base.rb index 3a85a2b..ea48272 100644 --- a/vendor/plugins/delayed_job/lib/delayed/backend/base.rb +++ b/vendor/plugins/delayed_job/lib/delayed/backend/base.rb @@ -73,9 +73,8 @@ module Delayed ParseObjectFromYaml = /\!ruby\/\w+\:([^\s]+)/ def name - @name ||= payload_object.respond_to?(:display_name) ? - payload_object.display_name : - payload_object.class.name + obj = payload_object + @name ||= obj.respond_to?(:display_name) ? obj.display_name : obj.class.name rescue DeserializationError ParseObjectFromYaml.match(handler)[1] end diff --git a/vendor/plugins/monkey_patches/init.rb b/vendor/plugins/monkey_patches/init.rb index 98c0650..928125f 100644 --- a/vendor/plugins/monkey_patches/init.rb +++ b/vendor/plugins/monkey_patches/init.rb @@ -1,3 +1,3 @@ -require File.join(File.dirname(__FILE__), 'attachment_fu_validates_attachment/init') -require File.join(File.dirname(__FILE__), 'attachment_fu/init') -require File.join(File.dirname(__FILE__), 'white_list_sanitizer_unescape_before_reescape/init') +require_relative 'attachment_fu_validates_attachment/init' +require_relative 'attachment_fu/init' +require_relative 'white_list_sanitizer_unescape_before_reescape/init' diff --git a/vendor/plugins/monkey_patches/rescue_delayed_job_crashes/init.rb b/vendor/plugins/monkey_patches/rescue_delayed_job_crashes/init.rb deleted file mode 100644 index 7ca59f5..0000000 --- a/vendor/plugins/monkey_patches/rescue_delayed_job_crashes/init.rb +++ /dev/null @@ -1,57 +0,0 @@ -Delayed::Worker.module_eval do - # based on https://groups.google.com/forum/#!topic/delayed_job/ZGMUFFppNgs - class Delayed::Worker::ExceptionNotification < ActionMailer::Base - def mail job, error - environment = Environment.default - - recipients NOOSFERO_CONF['exception_recipients'] - from environment.noreply_email - reply_to environment.noreply_email - subject "[#{environment.name}] DelayedJob ##{job.id}: #{error.message}" - body render(:text => " -Job: -#{job.inspect} - -Handler: -#{job.handler} - -Backtrace: -#{error.backtrace.join("\n")} - ") - end - end - - def handle_failed_job_with_notification(job, error) - Delayed::Worker::ExceptionNotification.deliver_mail job, error if NOOSFERO_CONF['exception_recipients'].present? - handle_failed_job_without_notification job, error - end - alias_method_chain :handle_failed_job, :notification - - def handle_failed_job_with_rescue(job, error) - handle_failed_job_without_rescue(job, error) - rescue => e # don't crash here - end - alias_method_chain :handle_failed_job, :rescue - - protected - - # This code must be replicated because there is no other way to pass the job - # through and use alias_method_chain as we used on the previous method - def reserve_and_run_one_job - # We get up to 5 jobs from the db. In case we cannot get exclusive access to a job we try the next. - # this leads to a more even distribution of jobs across the worker processes - job = Delayed::Job.find_available(name, 5, self.class.max_run_time).detect do |job| - if job.lock_exclusively!(self.class.max_run_time, name) - say "acquired lock on #{job.name}" - true - else - say "failed to acquire exclusive lock for #{job.name}", Logger::WARN - false - end - end - - run(job) if job - rescue => e - handle_failed_job(job, e) - end -end -- libgit2 0.21.2