diff --git a/app/jobs/gitlab_notifier_job.rb b/app/jobs/gitlab_notifier_job.rb index 701c6789..291112a5 100644 --- a/app/jobs/gitlab_notifier_job.rb +++ b/app/jobs/gitlab_notifier_job.rb @@ -37,7 +37,7 @@ class GitlabNotifierJob < ApplicationJob } end - unless @issue['iid'] + if @issue['iid'].blank? && issue_data[:issue].blank? Rails.cache.delete(cache_key) raise GitlabNotifierError, @issue.dig('message', 'title')&.join(', ') end @@ -62,8 +62,8 @@ class GitlabNotifierJob < ApplicationJob # Si este trabajo genera una excepción va a entrar en un loop, así que # la notificamos por correo rescue Exception => e - email_notification.call(e) - email_notification.call(exception, options) + email_notification.call(e, data: @issue) + email_notification.call(exception, data: options) end private @@ -84,10 +84,14 @@ class GitlabNotifierJob < ApplicationJob exception.class.name, Digest::SHA1.hexdigest(exception.message), Digest::SHA1.hexdigest(backtrace&.first.to_s), - Digest::SHA1.hexdigest(options.dig(:data, :params, 'errors').to_s) + Digest::SHA1.hexdigest(errors.to_s) ].join('/') end + def errors + options.dig(:data, :params, 'errors') if options.dig(:data, :params).is_a? Hash + end + # Define si es una excepción de javascript o local # # @see BacktraceJob @@ -126,6 +130,7 @@ class GitlabNotifierJob < ApplicationJob # @return [String] def body @body ||= ''.dup.tap do |b| + b << log_section b << request_section b << javascript_footer b << data_section @@ -162,14 +167,16 @@ class GitlabNotifierJob < ApplicationJob # @return [String] def log_section - return '' unless options[:log] + return '' unless options.dig(:data, :log) <<~LOG - # Log - ``` - #{options[:log]} - ``` + # Build log + + ``` + #{options[:data].delete(:log)} + ``` + LOG end @@ -257,8 +264,8 @@ class GitlabNotifierJob < ApplicationJob ## Data - ``` - #{pp options[:data]} + ```yaml + #{options[:data].to_yaml} ``` DATA diff --git a/config/initializers/sucker_punch.rb b/config/initializers/sucker_punch.rb index 865af32d..19506c2d 100644 --- a/config/initializers/sucker_punch.rb +++ b/config/initializers/sucker_punch.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true # Enviar una notificación cuando falla una tarea -SuckerPunch.exception_handler = lambda { |ex, _klass, _args| - ExceptionNotifier.notify_exception(ex) +SuckerPunch.exception_handler = lambda { |ex, _, args| + ExceptionNotifier.notify_exception(ex, data: args) }