From 8a5ecd98f75a9fcffefa68f8d0f9cb7516aa13c3 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 13 Mar 2023 20:31:16 -0300 Subject: [PATCH 01/17] fix: legible data, remove log section --- app/jobs/gitlab_notifier_job.rb | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/app/jobs/gitlab_notifier_job.rb b/app/jobs/gitlab_notifier_job.rb index 701c6789..5d9baa9e 100644 --- a/app/jobs/gitlab_notifier_job.rb +++ b/app/jobs/gitlab_notifier_job.rb @@ -112,7 +112,6 @@ class GitlabNotifierJob < ApplicationJob # @return [String] def description @description ||= ''.dup.tap do |d| - d << log_section d << request_section d << javascript_section d << javascript_footer @@ -160,19 +159,6 @@ class GitlabNotifierJob < ApplicationJob @client ||= GitlabApiClient.new end - # @return [String] - def log_section - return '' unless options[:log] - - <<~LOG - # Log - - ``` - #{options[:log]} - ``` - LOG - end - # Muestra información de la petición # # @return [String] @@ -257,8 +243,8 @@ class GitlabNotifierJob < ApplicationJob ## Data - ``` - #{pp options[:data]} + ```yaml + #{options[:data].to_yaml} ``` DATA From df3faba784dd47542101175a0d9aacc8606e31a8 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 13 Mar 2023 20:31:39 -0300 Subject: [PATCH 02/17] fix: send sucker punch args --- config/initializers/sucker_punch.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) } From 72f982ee7646b211e16a50d04fc41a0e1346efae Mon Sep 17 00:00:00 2001 From: f Date: Mon, 13 Mar 2023 20:42:40 -0300 Subject: [PATCH 03/17] fix: no fallar la segunda vez que se reporta el issue --- app/jobs/gitlab_notifier_job.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/jobs/gitlab_notifier_job.rb b/app/jobs/gitlab_notifier_job.rb index 5d9baa9e..d84ecda2 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,7 +62,7 @@ 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(e, data: @issue) email_notification.call(exception, options) end From 347aba67287fedae424c0d52c2728e84a1dec2c2 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 13 Mar 2023 20:47:54 -0300 Subject: [PATCH 04/17] feat: seccion de log --- app/jobs/gitlab_notifier_job.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/jobs/gitlab_notifier_job.rb b/app/jobs/gitlab_notifier_job.rb index d84ecda2..a127beaf 100644 --- a/app/jobs/gitlab_notifier_job.rb +++ b/app/jobs/gitlab_notifier_job.rb @@ -112,6 +112,7 @@ class GitlabNotifierJob < ApplicationJob # @return [String] def description @description ||= ''.dup.tap do |d| + d << log_section d << request_section d << javascript_section d << javascript_footer @@ -159,6 +160,21 @@ class GitlabNotifierJob < ApplicationJob @client ||= GitlabApiClient.new end + # @return [String] + def log_section + return if unless options.dig(:data, :log) + + <<~LOG + + # Build log + + ``` + #{option[:data].delete(:log)} + ``` + + LOG + end + # Muestra información de la petición # # @return [String] From 3764e14812309863a194a38efb17013414c3f88d Mon Sep 17 00:00:00 2001 From: f Date: Mon, 13 Mar 2023 20:49:00 -0300 Subject: [PATCH 05/17] fixup! feat: seccion de log --- app/jobs/gitlab_notifier_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/gitlab_notifier_job.rb b/app/jobs/gitlab_notifier_job.rb index a127beaf..7c785126 100644 --- a/app/jobs/gitlab_notifier_job.rb +++ b/app/jobs/gitlab_notifier_job.rb @@ -162,7 +162,7 @@ class GitlabNotifierJob < ApplicationJob # @return [String] def log_section - return if unless options.dig(:data, :log) + return '' unless options.dig(:data, :log) <<~LOG From 5fe0efeccd7dd1fb9a16f8d89f0d448528934cb0 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 13 Mar 2023 20:50:14 -0300 Subject: [PATCH 06/17] fixup! fixup! feat: seccion de log --- app/jobs/gitlab_notifier_job.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/jobs/gitlab_notifier_job.rb b/app/jobs/gitlab_notifier_job.rb index 7c785126..64caf977 100644 --- a/app/jobs/gitlab_notifier_job.rb +++ b/app/jobs/gitlab_notifier_job.rb @@ -126,6 +126,7 @@ class GitlabNotifierJob < ApplicationJob # @return [String] def body @body ||= ''.dup.tap do |b| + d << log_section b << request_section b << javascript_footer b << data_section From d166e669b7ce0e32ce9a0da07900f1dc675d992d Mon Sep 17 00:00:00 2001 From: f Date: Mon, 13 Mar 2023 20:51:28 -0300 Subject: [PATCH 07/17] fixup! fixup! fixup! feat: seccion de log --- app/jobs/gitlab_notifier_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/gitlab_notifier_job.rb b/app/jobs/gitlab_notifier_job.rb index 64caf977..edc6cf63 100644 --- a/app/jobs/gitlab_notifier_job.rb +++ b/app/jobs/gitlab_notifier_job.rb @@ -126,7 +126,7 @@ class GitlabNotifierJob < ApplicationJob # @return [String] def body @body ||= ''.dup.tap do |b| - d << log_section + b << log_section b << request_section b << javascript_footer b << data_section From b552b0fecd8be260f06cc9c5e6a300cc87a557fe Mon Sep 17 00:00:00 2001 From: f Date: Mon, 13 Mar 2023 20:52:30 -0300 Subject: [PATCH 08/17] fixup! fixup! fixup! fixup! feat: seccion de log --- app/jobs/gitlab_notifier_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/gitlab_notifier_job.rb b/app/jobs/gitlab_notifier_job.rb index edc6cf63..c8daf220 100644 --- a/app/jobs/gitlab_notifier_job.rb +++ b/app/jobs/gitlab_notifier_job.rb @@ -170,7 +170,7 @@ class GitlabNotifierJob < ApplicationJob # Build log ``` - #{option[:data].delete(:log)} + #{options[:data].delete(:log)} ``` LOG From 5822a9b661eecc331f422fb22c5b8365516522d2 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 14 Mar 2023 16:10:59 -0300 Subject: [PATCH 09/17] =?UTF-8?q?fix:=20enviar=20m=C3=A1s=20informaci?= =?UTF-8?q?=C3=B3n=20con=20el=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #10064 closes #10065 closes #10066 closes #10067 closes #10068 closes #10069 closes #10070 closes #10071 closes #10072 closes #10073 closes #10074 closes #10075 closes #10076 closes #10077 closes #10078 closes #10079 closes #10080 closes #10081 closes #10082 closes #10083 closes #10084 closes #10085 closes #10086 closes #10087 closes #10088 closes #10089 closes #10090 closes #10091 closes #10092 closes #10093 closes #10094 closes #10095 closes #10096 closes #10097 closes #10098 closes #10099 closes #10100 closes #10101 closes #10102 closes #10103 closes #10104 closes #10105 closes #10106 closes #10107 closes #10108 closes #10109 closes #10110 closes #10111 closes #10112 closes #10113 closes #10114 closes #10115 closes #10116 closes #10117 closes #10118 closes #10119 closes #10120 closes #10121 closes #10122 closes #10123 closes #10124 closes #10125 closes #10126 closes #10127 closes #10128 closes #10129 closes #10130 closes #10131 closes #10132 closes #10133 closes #10134 closes #10135 closes #10136 closes #10137 closes #10138 closes #10139 closes #10140 closes #10141 closes #10142 closes #10143 closes #10144 closes #10145 closes #10146 closes #10147 closes #10148 closes #10149 closes #10150 closes #10151 closes #10152 closes #10153 closes #10154 closes #10155 closes #10156 closes #10157 closes #10158 closes #10159 closes #10160 closes #10161 closes #10162 closes #10163 closes #10164 closes #10165 closes #10166 closes #10167 closes #10168 closes #10169 closes #10170 closes #10171 closes #10172 closes #10173 closes #10174 closes #10175 closes #10176 closes #10177 closes #10178 closes #10179 closes #10180 closes #10181 closes #10182 closes #10183 closes #10184 closes #10185 closes #10186 closes #10187 closes #10188 closes #10189 closes #10190 closes #10191 closes #10192 closes #10193 closes #10194 closes #10195 closes #10196 closes #10197 closes #10198 closes #10199 closes #10200 closes #10201 closes #10202 closes #10203 closes #10204 closes #10205 closes #10206 closes #10207 closes #10208 closes #10209 closes #10210 closes #10211 closes #10212 closes #10213 closes #10214 closes #10215 closes #10216 closes #10217 closes #10218 closes #10219 closes #10220 closes #10221 closes #10222 closes #10223 closes #10224 closes #10225 closes #10226 closes #10227 closes #10228 closes #10229 closes #10230 closes #10231 closes #10232 closes #10234 closes #10235 closes #10236 closes #10237 closes #10238 closes #10239 closes #10240 closes #10241 closes #10242 closes #10243 closes #10244 --- app/jobs/gitlab_notifier_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/gitlab_notifier_job.rb b/app/jobs/gitlab_notifier_job.rb index c8daf220..11d4274a 100644 --- a/app/jobs/gitlab_notifier_job.rb +++ b/app/jobs/gitlab_notifier_job.rb @@ -63,7 +63,7 @@ class GitlabNotifierJob < ApplicationJob # la notificamos por correo rescue Exception => e email_notification.call(e, data: @issue) - email_notification.call(exception, options) + email_notification.call(exception, data: options) end private From 6f363f2c358a63d6ad74c2c0d962ca93f148c06b Mon Sep 17 00:00:00 2001 From: f Date: Tue, 14 Mar 2023 16:16:46 -0300 Subject: [PATCH 10/17] fix: params a veces es un array?? --- app/jobs/gitlab_notifier_job.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/jobs/gitlab_notifier_job.rb b/app/jobs/gitlab_notifier_job.rb index 11d4274a..291112a5 100644 --- a/app/jobs/gitlab_notifier_job.rb +++ b/app/jobs/gitlab_notifier_job.rb @@ -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 From 5ec698366a524583063cefb84d652084e2841788 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 20 Mar 2023 11:46:21 -0300 Subject: [PATCH 11/17] fix: capturar standard error --- app/jobs/gitlab_notifier_job.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/jobs/gitlab_notifier_job.rb b/app/jobs/gitlab_notifier_job.rb index 291112a5..fb25be10 100644 --- a/app/jobs/gitlab_notifier_job.rb +++ b/app/jobs/gitlab_notifier_job.rb @@ -61,7 +61,7 @@ class GitlabNotifierJob < ApplicationJob Rails.cache.write(cache_key, issue_data) # Si este trabajo genera una excepción va a entrar en un loop, así que # la notificamos por correo - rescue Exception => e + rescue StandardError => e email_notification.call(e, data: @issue) email_notification.call(exception, data: options) end @@ -89,7 +89,9 @@ class GitlabNotifierJob < ApplicationJob end def errors - options.dig(:data, :params, 'errors') if options.dig(:data, :params).is_a? Hash + return '' unless javascript? + + options.dig(:data, :params, 'errors') end # Define si es una excepción de javascript o local From d25937f536ef072f2a9323b03e1bbaa4809fcd40 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 20 Mar 2023 15:33:28 -0300 Subject: [PATCH 12/17] fix: no producir type error --- app/jobs/gitlab_notifier_job.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/jobs/gitlab_notifier_job.rb b/app/jobs/gitlab_notifier_job.rb index fb25be10..2f39caf9 100644 --- a/app/jobs/gitlab_notifier_job.rb +++ b/app/jobs/gitlab_notifier_job.rb @@ -16,7 +16,7 @@ class GitlabNotifierJob < ApplicationJob # @param [Hash] opciones de ExceptionNotifier def perform(exception, **options) @exception = exception - @options = options + @options = fix_options options @issue_data = { count: 1 } # Necesitamos saber si el issue ya existía @cached = false @@ -88,10 +88,9 @@ class GitlabNotifierJob < ApplicationJob ].join('/') end + # @return [Array] def errors - return '' unless javascript? - - options.dig(:data, :params, 'errors') + options.dig(:data, :params, 'errors') || [] end # Define si es una excepción de javascript o local @@ -288,4 +287,15 @@ class GitlabNotifierJob < ApplicationJob def url @url ||= request&.url || options.dig(:data, :params, 'context', 'url') end + + # Define llaves necesarias + # + # @param :options [Hash] + # @return [Hash] + def fix_options(options) + options[:data] ||= {} + options[:data][:params] ||= {} + + options + end end From 706ff80b1864b791197741ff5afbd98ab808baae Mon Sep 17 00:00:00 2001 From: f Date: Tue, 21 Mar 2023 14:05:11 -0300 Subject: [PATCH 13/17] =?UTF-8?q?fix:=20algo=20est=C3=A1=20enviando=20las?= =?UTF-8?q?=20opciones=20como=20array?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/gitlab_notifier_job.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/jobs/gitlab_notifier_job.rb b/app/jobs/gitlab_notifier_job.rb index 2f39caf9..4d57c744 100644 --- a/app/jobs/gitlab_notifier_job.rb +++ b/app/jobs/gitlab_notifier_job.rb @@ -293,6 +293,7 @@ class GitlabNotifierJob < ApplicationJob # @param :options [Hash] # @return [Hash] def fix_options(options) + options = { data: options } if options.is_a? Array options[:data] ||= {} options[:data][:params] ||= {} From 1230dc2e96eb2bc117f1f92433e0d97748d4f2bf Mon Sep 17 00:00:00 2001 From: f Date: Wed, 22 Mar 2023 09:58:00 -0300 Subject: [PATCH 14/17] fix: solo permitimos un hash de opciones --- app/jobs/gitlab_notifier_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/gitlab_notifier_job.rb b/app/jobs/gitlab_notifier_job.rb index 4d57c744..7b369fab 100644 --- a/app/jobs/gitlab_notifier_job.rb +++ b/app/jobs/gitlab_notifier_job.rb @@ -293,7 +293,7 @@ class GitlabNotifierJob < ApplicationJob # @param :options [Hash] # @return [Hash] def fix_options(options) - options = { data: options } if options.is_a? Array + options = { data: options } unless options.is_a? Hash options[:data] ||= {} options[:data][:params] ||= {} From bbb951594b8594d6d71943b77c077573d813b8e1 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 22 Mar 2023 09:59:36 -0300 Subject: [PATCH 15/17] fix: enviar las opciones post limpieza --- app/jobs/gitlab_notifier_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/gitlab_notifier_job.rb b/app/jobs/gitlab_notifier_job.rb index 7b369fab..575d57d8 100644 --- a/app/jobs/gitlab_notifier_job.rb +++ b/app/jobs/gitlab_notifier_job.rb @@ -63,7 +63,7 @@ class GitlabNotifierJob < ApplicationJob # la notificamos por correo rescue StandardError => e email_notification.call(e, data: @issue) - email_notification.call(exception, data: options) + email_notification.call(exception, data: @options) end private From 5cda6a440c00879b3ba6418c208fb2af9b8852b5 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 23 Mar 2023 14:11:19 -0300 Subject: [PATCH 16/17] fix: enviar los argumentos como un hash closes ##12742 closes ##12740 closes ##12734 closes ##12732 closes ##12725 closes ##12721 closes ##12718 closes ##12715 --- config/initializers/sucker_punch.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/sucker_punch.rb b/config/initializers/sucker_punch.rb index 19506c2d..ce1209dd 100644 --- a/config/initializers/sucker_punch.rb +++ b/config/initializers/sucker_punch.rb @@ -2,5 +2,5 @@ # Enviar una notificación cuando falla una tarea SuckerPunch.exception_handler = lambda { |ex, _, args| - ExceptionNotifier.notify_exception(ex, data: args) + ExceptionNotifier.notify_exception(ex, data: { args: args }) } From 98b38e4caabcfa354b4d90e05112d1031fefcf7a Mon Sep 17 00:00:00 2001 From: f Date: Thu, 23 Mar 2023 15:14:53 -0300 Subject: [PATCH 17/17] =?UTF-8?q?fix:=20el=20=C3=BAltimo=20=C3=ADtem=20es?= =?UTF-8?q?=20un=20hash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #12747 --- config/initializers/sucker_punch.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/sucker_punch.rb b/config/initializers/sucker_punch.rb index ce1209dd..21997139 100644 --- a/config/initializers/sucker_punch.rb +++ b/config/initializers/sucker_punch.rb @@ -2,5 +2,5 @@ # Enviar una notificación cuando falla una tarea SuckerPunch.exception_handler = lambda { |ex, _, args| - ExceptionNotifier.notify_exception(ex, data: { args: args }) + ExceptionNotifier.notify_exception(ex, data: args.last) }