From d7de351e1af36ab1383d2cf0c4e8f040fef6a686 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 25 Mar 2024 13:32:08 -0300 Subject: [PATCH 1/4] fix: espaciar el procesamiento de tareas closes #15621 closes #15622 closes #15623 closes #15729 closes #15730 closes #15731 closes #15735 closes #15736 closes #15824 --- .../api/v1/webhooks/social_inbox_controller.rb | 4 +++- app/jobs/application_job.rb | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/webhooks/social_inbox_controller.rb b/app/controllers/api/v1/webhooks/social_inbox_controller.rb index 6ac91a51..9d215812 100644 --- a/app/controllers/api/v1/webhooks/social_inbox_controller.rb +++ b/app/controllers/api/v1/webhooks/social_inbox_controller.rb @@ -49,7 +49,9 @@ module Api # # @param initial_state [Symbol] def process!(initial_state) - ::ActivityPub::ProcessJob.perform_later(site: site, body: request.raw_post, initial_state: initial_state) + ::ActivityPub::ProcessJob + .set(wait: ApplicationJob.random_wait) + .perform_later(site: site, body: request.raw_post, initial_state: initial_state) end end end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index 06690c53..1bf20345 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -4,6 +4,17 @@ class ApplicationJob < ActiveJob::Base include Que::ActiveJob::JobExtensions + # Esperar una cantidad random de segundos primos, para que no se + # superpongan tareas + # + # @return [Array] + RANDOM_WAIT = [3, 5, 7, 11, 13].seconds + + # @return [ActiveSupport::Duration] + def self.random_wait + RANDOM_WAIT.sample + end + private def site From 718b8643562f2f1d3202ed3c0a7ded93a115ceb5 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 25 Mar 2024 13:33:52 -0300 Subject: [PATCH 2/4] fixup! fix: espaciar el procesamiento de tareas --- app/jobs/application_job.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index 1bf20345..dc6d0478 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -7,12 +7,12 @@ class ApplicationJob < ActiveJob::Base # Esperar una cantidad random de segundos primos, para que no se # superpongan tareas # - # @return [Array] - RANDOM_WAIT = [3, 5, 7, 11, 13].seconds + # @return [Array] + RANDOM_WAIT = [3, 5, 7, 11, 13] # @return [ActiveSupport::Duration] def self.random_wait - RANDOM_WAIT.sample + RANDOM_WAIT.sample.seconds end private From 88cc5f9cb0adee2eca01b5b905d69dd6f160fd37 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 25 Mar 2024 14:17:26 -0300 Subject: [PATCH 3/4] 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 From 0d28748b8b65192f59af90869e02cef44fd0a50c Mon Sep 17 00:00:00 2001 From: f Date: Tue, 26 Mar 2024 11:42:29 -0300 Subject: [PATCH 4/4] fix: i18n --- config/locales/en.yml | 5 +---- config/locales/es.yml | 4 +--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index f024fa98..1c9f4576 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -771,10 +771,7 @@ en: categories: 'Everything' index: search: 'Search' - edit_post: 'Edit' - edit: - moderation_queue: Moderation Queue - post: Post + edit: Edit preview: btn: 'Preliminary version' alert: 'Not every article type has a preliminary version' diff --git a/config/locales/es.yml b/config/locales/es.yml index 204a3587..a96d5e60 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -712,9 +712,7 @@ es: en: 'inglés' ar: 'árabe' posts: - edit: - moderation_queue: Comentarios - post: Contenido + edit: Editar prev: Página anterior next: Página siguiente empty: No hay artículos con estos parámetros de búsqueda.