chore: Move Whatsapp template sync to cron (#4858)
syncing WhatsApp templates job is moved to a cron job for a better user experience. The Templates are synced at 15-minute intervals now.
This commit is contained in:
7
app/jobs/channels/whatsapp/templates_sync_job.rb
Normal file
7
app/jobs/channels/whatsapp/templates_sync_job.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class Channels::Whatsapp::TemplatesSyncJob < ApplicationJob
|
||||
queue_as :low
|
||||
|
||||
def perform(whatsapp_channel)
|
||||
whatsapp_channel.sync_templates
|
||||
end
|
||||
end
|
||||
12
app/jobs/channels/whatsapp/templates_sync_scheduler_job.rb
Normal file
12
app/jobs/channels/whatsapp/templates_sync_scheduler_job.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
class Channels::Whatsapp::TemplatesSyncSchedulerJob < ApplicationJob
|
||||
queue_as :low
|
||||
|
||||
def perform
|
||||
Channel::Whatsapp.where('message_templates_last_updated <= ? OR message_templates_last_updated IS NULL',
|
||||
15.minutes.ago).find_in_batches do |channels_batch|
|
||||
channels_batch.each do |channel|
|
||||
Channels::Whatsapp::TemplatesSyncJob.perform_later(channel)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -12,5 +12,8 @@ class TriggerScheduledItemsJob < ApplicationJob
|
||||
|
||||
# Job to auto-resolve conversations
|
||||
Account::ConversationsResolutionSchedulerJob.perform_later
|
||||
|
||||
# Job to sync whatsapp templates
|
||||
Channels::Whatsapp::TemplatesSyncSchedulerJob.perform_later
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user