[noosfero/noosfero][master] 2 commits: delayed_job: port exception notifications to rails 3
Bráulio Bhavamitra
gitlab at gitlab.com
Tue Jun 2 15:37:22 BRT 2015
Bráulio Bhavamitra pushed to branch master at Noosfero / noosfero
Commits:
c9a234ca by Braulio Bhavamitra at 2015-05-20T21:13:02Z
delayed_job: port exception notifications to rails 3
- - - - -
c51caedd by Bráulio Bhavamitra at 2015-06-02T18:37:09Z
Merge branch 'delayed-job-exception-notification' into 'master'
delayed_job: port exception notifications to rails 3
See merge request !580
- - - - -
4 changed files:
- config/initializers/delayed_job_config.rb
- vendor/plugins/delayed_job/lib/delayed/backend/base.rb
- vendor/plugins/monkey_patches/init.rb
- − vendor/plugins/monkey_patches/rescue_delayed_job_crashes/init.rb
Changes:
=====================================
config/initializers/delayed_job_config.rb
=====================================
--- 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
=====================================
vendor/plugins/delayed_job/lib/delayed/backend/base.rb
=====================================
--- 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
=====================================
vendor/plugins/monkey_patches/init.rb
=====================================
--- 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'
=====================================
vendor/plugins/monkey_patches/rescue_delayed_job_crashes/init.rb deleted
=====================================
--- 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
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/0bf5c21e5e02a4538df5033513072676d6c953c6...c51caedd718da2f1edafee0e075ca1cbeb776b2b
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150602/cb6f7141/attachment-0001.html>
More information about the Noosfero-dev
mailing list