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