From 6bb3cbf53f9fa18feb01eddede9963f932ba1e55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Denquin?= Date: Wed, 18 Dec 2024 16:29:00 +0100 Subject: [PATCH] chore(scalability): Add dedicated webhook worker (#2979) - Add a webhook worker --- app/jobs/send_http_webhook_job.rb | 8 ++++++++ app/jobs/send_webhook_job.rb | 8 +++++++- config/sidekiq/sidekiq_webhook.yml | 10 ++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 config/sidekiq/sidekiq_webhook.yml diff --git a/app/jobs/send_http_webhook_job.rb b/app/jobs/send_http_webhook_job.rb index cc27517aeff..fa0082a790a 100644 --- a/app/jobs/send_http_webhook_job.rb +++ b/app/jobs/send_http_webhook_job.rb @@ -1,6 +1,14 @@ # frozen_string_literal: true class SendHttpWebhookJob < ApplicationJob + queue_as do + if ActiveModel::Type::Boolean.new.cast(ENV['SIDEKIQ_WEBHOOK']) + :webhook_worker + else + :webhook + end + end + def perform(webhook) Webhooks::SendHttpService.call(webhook:) end diff --git a/app/jobs/send_webhook_job.rb b/app/jobs/send_webhook_job.rb index f9f542e4e8b..4c6fdd41aa4 100644 --- a/app/jobs/send_webhook_job.rb +++ b/app/jobs/send_webhook_job.rb @@ -3,7 +3,13 @@ require Rails.root.join('lib/lago_http_client/lago_http_client') class SendWebhookJob < ApplicationJob - queue_as 'webhook' + queue_as do + if ActiveModel::Type::Boolean.new.cast(ENV['SIDEKIQ_WEBHOOK']) + :webhook_worker + else + :webhook + end + end retry_on ActiveJob::DeserializationError, wait: :polynomially_longer, attempts: 6 diff --git a/config/sidekiq/sidekiq_webhook.yml b/config/sidekiq/sidekiq_webhook.yml new file mode 100644 index 00000000000..00ecbf8bc4f --- /dev/null +++ b/config/sidekiq/sidekiq_webhook.yml @@ -0,0 +1,10 @@ +concurrency: 10 +timeout: 25 +retry: 1 +queues: + - webhook_worker + +production: + concurrency: <%= ENV.fetch('SIDEKIQ_CONCURRENCY', 10) %> +staging: + concurrency: 10