chore: enable stale contact removal job on chatwoot cloud (#11390)

- enable stale contact/contact inboxes removal job on chatwoot cloud
This commit is contained in:
Vishnu Narayanan
2025-05-02 13:36:30 +05:30
committed by GitHub
parent 55316ea0a0
commit f3a807c6f0
3 changed files with 20 additions and 6 deletions

View File

@@ -8,6 +8,8 @@ class Internal::ProcessStaleContactsJob < ApplicationJob
queue_as :scheduled_jobs
def perform
return unless ChatwootApp.chatwoot_cloud?
Account.find_in_batches(batch_size: 100) do |accounts|
accounts.each do |account|
Rails.logger.info "Enqueuing RemoveStaleContactsJob for account #{account.id}"

View File

@@ -33,9 +33,9 @@ remove_stale_redis_keys_job.rb:
class: 'Internal::RemoveStaleRedisKeysJob'
queue: scheduled_jobs
# executed daily at 2230 UTC
# which is our lowest traffic time
# process_stale_contacts_job:
# cron: '30 22 * * *'
# class: 'Internal::ProcessStaleContactsJob'
# queue: scheduled_jobs
#executed daily at 0430 UTC
# which will be IST 10:00 AM
process_stale_contacts_job:
cron: '30 04 * * *'
class: 'Internal::ProcessStaleContactsJob'
queue: scheduled_jobs

View File

@@ -4,11 +4,13 @@ RSpec.describe Internal::ProcessStaleContactsJob do
subject(:job) { described_class.perform_later }
it 'enqueues the job' do
allow(ChatwootApp).to receive(:chatwoot_cloud?).and_return(true)
expect { job }.to have_enqueued_job(described_class)
.on_queue('scheduled_jobs')
end
it 'enqueues RemoveStaleContactsJob for each account' do
allow(ChatwootApp).to receive(:chatwoot_cloud?).and_return(true)
account1 = create(:account)
account2 = create(:account)
account3 = create(:account)
@@ -25,10 +27,20 @@ RSpec.describe Internal::ProcessStaleContactsJob do
end
it 'processes accounts in batches' do
allow(ChatwootApp).to receive(:chatwoot_cloud?).and_return(true)
account = create(:account)
allow(Account).to receive(:find_in_batches).with(batch_size: 100).and_yield([account])
expect(Internal::RemoveStaleContactsJob).to receive(:perform_later).with(account)
described_class.perform_now
end
it 'does not process accounts when not in cloud environment' do
allow(ChatwootApp).to receive(:chatwoot_cloud?).and_return(false)
create(:account)
expect(Account).not_to receive(:find_in_batches)
expect(Internal::RemoveStaleContactsJob).not_to receive(:perform_later)
described_class.perform_now
end
end