From 081e08c7c6be78c3745cfc68e792e561f5472796 Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Fri, 17 Jul 2026 11:57:07 +0400 Subject: [PATCH] fix(whatsapp): skip template sync for suspended accounts (#15047) Suspended accounts no longer participate in scheduled WhatsApp template syncs. This avoids unnecessary external API calls while keeping the existing refresh behavior unchanged for active accounts. Co-authored-by: Muhsin <12408980+muhsin-k@users.noreply.github.com> --- .../whatsapp/templates_sync_scheduler_job.rb | 4 +++- .../templates_sync_scheduler_job_spec.rb | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/jobs/channels/whatsapp/templates_sync_scheduler_job.rb b/app/jobs/channels/whatsapp/templates_sync_scheduler_job.rb index 6a5e6cb2b..8cbc5a0ff 100644 --- a/app/jobs/channels/whatsapp/templates_sync_scheduler_job.rb +++ b/app/jobs/channels/whatsapp/templates_sync_scheduler_job.rb @@ -2,7 +2,9 @@ class Channels::Whatsapp::TemplatesSyncSchedulerJob < ApplicationJob queue_as :low def perform - Channel::Whatsapp.order(Arel.sql('message_templates_last_updated IS NULL DESC, message_templates_last_updated ASC')) + Channel::Whatsapp.joins(:account) + .merge(Account.active) + .order(Arel.sql('message_templates_last_updated IS NULL DESC, message_templates_last_updated ASC')) .where('message_templates_last_updated <= ? OR message_templates_last_updated IS NULL', 3.hours.ago) .limit(Limits::BULK_EXTERNAL_HTTP_CALLS_LIMIT) .each do |channel| diff --git a/spec/jobs/channels/whatsapp/templates_sync_scheduler_job_spec.rb b/spec/jobs/channels/whatsapp/templates_sync_scheduler_job_spec.rb index cf0b30842..bd47afc23 100644 --- a/spec/jobs/channels/whatsapp/templates_sync_scheduler_job_spec.rb +++ b/spec/jobs/channels/whatsapp/templates_sync_scheduler_job_spec.rb @@ -24,6 +24,23 @@ RSpec.describe Channels::Whatsapp::TemplatesSyncSchedulerJob do ) end + it 'does not schedule templates_sync_jobs for suspended accounts' do + stub_request(:post, 'https://waba.360dialog.io/v1/configs/webhook') + suspended_account = create(:account, status: :suspended) + suspended_channel = create( + :channel_whatsapp, + account: suspended_account, + sync_templates: false, + message_templates_last_updated: nil + ) + + described_class.perform_now + + expect(Channels::Whatsapp::TemplatesSyncJob).not_to( + have_been_enqueued.with(suspended_channel).on_queue('low') + ) + end + it 'schedules templates_sync_job for oldest synced channels first' do stub_const('Limits::BULK_EXTERNAL_HTTP_CALLS_LIMIT', 2) stub_request(:post, 'https://waba.360dialog.io/v1/configs/webhook')