From d7de351e1af36ab1383d2cf0c4e8f040fef6a686 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 25 Mar 2024 13:32:08 -0300 Subject: [PATCH] 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