From 20e8e83ab601168214974333e69a2968970a9c2a Mon Sep 17 00:00:00 2001 From: f Date: Mon, 10 Apr 2023 13:28:01 -0300 Subject: [PATCH 1/6] feat: notificar errores de que --- config/initializers/que.rb | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 config/initializers/que.rb diff --git a/config/initializers/que.rb b/config/initializers/que.rb new file mode 100644 index 00000000..d7abfeb5 --- /dev/null +++ b/config/initializers/que.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +ActiveJob::Serializers.add_serializers ActiveJob::Serializers::ExceptionSerializer + +# Notificar los errores +Que.error_notifier = proc do |error, job| + ExceptionNotifier.notify_exception(error, data: (job || {})) +end From a58936b22ecc2e70903c89d8dcf8e501d00f6642 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 10 Apr 2023 13:28:32 -0300 Subject: [PATCH 2/6] =?UTF-8?q?fix:=20retomar=20la=20publicaci=C3=B3n=20de?= =?UTF-8?q?=20cambios=20#12958?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/deploy_job.rb | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index aeb0f4b6..a7f59afb 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -4,9 +4,23 @@ class DeployJob < ApplicationJob class DeployException < StandardError; end class DeployTimedOutException < DeployException; end + class DeployAlreadyRunningException < DeployException; end discard_on ActiveRecord::RecordNotFound + # Lanzar lo antes posible + self.priority = 10 + # Intentar dentro de un minuto + self.retry_interval = 60 + + def handle_error(error) + case error + when DeployAlreadyRunningException then retry_in 1.minute + when DeployTimedOutException then expire + else super + end + end + # rubocop:disable Metrics/MethodLength def perform(site, notify: true, time: Time.now, output: false) @output = output @@ -20,14 +34,14 @@ class DeployJob < ApplicationJob # Como el trabajo actual se aplaza al siguiente, arrastrar la # hora original para poder ir haciendo timeouts. if @site.building? + notify = false + if 10.minutes.ago >= time - notify = false raise DeployTimedOutException, "#{@site.name} la tarea estuvo más de 10 minutos esperando, volviendo al estado original" + else + raise DeployAlreadyRunningException end - - DeployJob.perform_in(60, site, notify: notify, time: time, output: output) - return end @deployed = {} @@ -67,8 +81,6 @@ class DeployJob < ApplicationJob t << ([type.to_s] + row.values) end end) - rescue DeployTimedOutException => e - notify_exception e ensure if @site.present? @site.update status: 'waiting' From 79f3958a0697d16c59b079da86db601bdf1abf90 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 10 Apr 2023 16:53:35 -0300 Subject: [PATCH 3/6] fix: que no expone este metodo en activejob --- app/jobs/deploy_job.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index a7f59afb..a5cda360 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -10,8 +10,6 @@ class DeployJob < ApplicationJob # Lanzar lo antes posible self.priority = 10 - # Intentar dentro de un minuto - self.retry_interval = 60 def handle_error(error) case error From 6c1dcf5ded419363690844a3a66eda6047c9d0bd Mon Sep 17 00:00:00 2001 From: f Date: Mon, 10 Apr 2023 17:31:26 -0300 Subject: [PATCH 4/6] =?UTF-8?q?fix:=20evitar=20errores=20de=20serializaci?= =?UTF-8?q?=C3=B3n=20#12998?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `que` falla silenciosamente cuando no puede serializar errores para enviar, que es la mayor parte de las veces. enviar los errores sincronicamente excepto los de airbrake --- app/lib/exception_notifier/gitlab_notifier.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/lib/exception_notifier/gitlab_notifier.rb b/app/lib/exception_notifier/gitlab_notifier.rb index 18bfc6d4..8152bb62 100644 --- a/app/lib/exception_notifier/gitlab_notifier.rb +++ b/app/lib/exception_notifier/gitlab_notifier.rb @@ -11,7 +11,12 @@ module ExceptionNotifier # @param [Exception] # @param [Hash] def call(exception, **options) - GitlabNotifierJob.perform_async(exception, **options) + case exception + when BacktraceJob::BacktraceException + GitlabNotifierJob.perform_later(exception, **options) + else + GitlabNotifierJob.perform_now(exception, **options) + end end end end From 482a63720793508f03e8756d575ea2d39021ff5d Mon Sep 17 00:00:00 2001 From: f Date: Mon, 10 Apr 2023 17:33:07 -0300 Subject: [PATCH 5/6] fix: perform_later --- app/controllers/api/v1/contact_controller.rb | 2 +- app/jobs/maintenance_job.rb | 2 +- app/models/log_entry.rb | 2 +- app/services/site_service.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/v1/contact_controller.rb b/app/controllers/api/v1/contact_controller.rb index deacf4a7..d949dc30 100644 --- a/app/controllers/api/v1/contact_controller.rb +++ b/app/controllers/api/v1/contact_controller.rb @@ -18,7 +18,7 @@ module Api # Si todo salió bien, enviar los correos y redirigir al sitio. # El sitio nos dice a dónde tenemos que ir. - ContactJob.perform_async site.id, + ContactJob.perform_later site.id, params[:form], contact_params.to_h.symbolize_keys, params[:redirect] diff --git a/app/jobs/maintenance_job.rb b/app/jobs/maintenance_job.rb index 4c411d0e..c7a962f9 100644 --- a/app/jobs/maintenance_job.rb +++ b/app/jobs/maintenance_job.rb @@ -10,7 +10,7 @@ # bundle exec rails c # m = Maintenance.create message_en: 'reason', message_es: 'razón', # estimated_from: Time.now, estimated_to: Time.now + 1.hour -# MaintenanceJob.perform_async(maintenance_id: m.id) +# MaintenanceJob.perform_later(maintenance_id: m.id) # # Lo mismo para salir de mantenimiento, agregando el atributo # are_we_back: true al crear el Maintenance. diff --git a/app/models/log_entry.rb b/app/models/log_entry.rb index 1824da55..9685e0d0 100644 --- a/app/models/log_entry.rb +++ b/app/models/log_entry.rb @@ -11,7 +11,7 @@ class LogEntry < ApplicationRecord def resend return if sent - ContactJob.perform_async site_id, params[:form], params + ContactJob.perform_later site_id, params[:form], params end def params diff --git a/app/services/site_service.rb b/app/services/site_service.rb index 8ecc3f56..5d28bf91 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -5,7 +5,7 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do def deploy site.enqueue! - DeployJob.perform_async site.id + DeployJob.perform_later site.id end # Crea un sitio, agrega un rol nuevo y guarda los cambios a la From 1e79e2687295d8c12ded65c0ccb2e82f8f144346 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 10 Apr 2023 17:38:16 -0300 Subject: [PATCH 6/6] fix: ignorar las excepciones de publicaciones duplicadas --- config/environments/production.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index d121bdbd..653ca8aa 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -147,7 +147,7 @@ Rails.application.configure do } config.action_mailer.default_options = { from: ENV.fetch('DEFAULT_FROM', "noreply@sutty.nl") } - config.middleware.use ExceptionNotification::Rack, gitlab: {} + config.middleware.use ExceptionNotification::Rack, gitlab: {}, ignore_exceptions: (['DeployJob::DeployAlreadyRunningException'] + ExceptionNotifier.ignored_exceptions) Rails.application.routes.default_url_options[:host] = "panel.#{ENV.fetch('SUTTY', 'sutty.nl')}" Rails.application.routes.default_url_options[:protocol] = 'https'