From 88cc5f9cb0adee2eca01b5b905d69dd6f160fd37 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 25 Mar 2024 14:17:26 -0300 Subject: [PATCH] fix: reintentar antes de reportar el error #15824 --- app/jobs/activity_pub/process_job.rb | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/app/jobs/activity_pub/process_job.rb b/app/jobs/activity_pub/process_job.rb index af686dbd..d94c31e2 100644 --- a/app/jobs/activity_pub/process_job.rb +++ b/app/jobs/activity_pub/process_job.rb @@ -3,15 +3,16 @@ class ActivityPub # Procesar las actividades a medida que llegan class ProcessJob < ApplicationJob - attr_reader :body + attr_reader :body, :initial_state # Procesa la actividad en segundo plano # # @param :body [String] # @param :initial_state [Symbol,String] def perform(site:, body:, initial_state: :paused) - @body = body @site = site + @body = body + @initial_state = initial_state ActiveRecord::Base.connection_pool.with_connection do ::ActivityPub.transaction do @@ -25,10 +26,24 @@ class ActivityPub activity.update_activity_pub_state! end end + end + # Al generar una excepción, en lugar de seguir intentando, enviamos # el reporte. - rescue Exception => e - ExceptionNotifier.notify_exception(e, data: { site: site.name, body: body, initial_state: initial_state, activity: original_activity, message: 'Esta acción se canceló automáticamente, para regenerarla, volver a correr el proceso con los mismos parámetros.' }) + def handle_error(error) + case error + when ActiveRecord::RecordInvalid then retry_in(ApplicationJob.random_wait) + else + ExceptionNotifier.notify_exception( + error, + data: { + site: site.name, + body: body, + initial_state: initial_state, + activity: original_activity, + message: 'Esta acción se canceló automáticamente, para regenerarla, volver a correr el proceso con los mismos parámetros.' + }) + end end private