chore: Reorganize Sidekiq Queues (#6976)

- Rearrange and reprioritize current sidekiq queues
- Trim the unnecessary queues

ref: https://linear.app/chatwoot/issue/CW-1480/chore-run-all-sidekiq-jobs-async
This commit is contained in:
Sojan Jose
2023-05-04 15:44:16 +05:30
committed by GitHub
parent b081fe08b8
commit 85e57c2e94
23 changed files with 38 additions and 39 deletions

View File

@@ -1,5 +1,5 @@
class ActionCableBroadcastJob < ApplicationJob class ActionCableBroadcastJob < ApplicationJob
queue_as :default queue_as :critical
def perform(members, event_name, data) def perform(members, event_name, data)
members.each do |member| members.each do |member|

View File

@@ -1,5 +1,5 @@
class AgentBots::CsmlJob < ApplicationJob class AgentBots::CsmlJob < ApplicationJob
queue_as :bots queue_as :high
def perform(event, agent_bot, message) def perform(event, agent_bot, message)
event_data = { message: message } event_data = { message: message }

View File

@@ -1,3 +1,3 @@
class AgentBots::WebhookJob < WebhookJob class AgentBots::WebhookJob < WebhookJob
queue_as :bots queue_as :high
end end

View File

@@ -1,5 +1,5 @@
class Agents::DestroyJob < ApplicationJob class Agents::DestroyJob < ApplicationJob
queue_as :default queue_as :low
def perform(account, user) def perform(account, user)
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do

View File

@@ -1,5 +1,5 @@
class Avatar::AvatarFromUrlJob < ApplicationJob class Avatar::AvatarFromUrlJob < ApplicationJob
queue_as :default queue_as :low
def perform(avatarable, avatar_url) def perform(avatarable, avatar_url)
return unless avatarable.respond_to?(:avatar) return unless avatarable.respond_to?(:avatar)

View File

@@ -1,5 +1,5 @@
class Conversations::ActivityMessageJob < ApplicationJob class Conversations::ActivityMessageJob < ApplicationJob
queue_as :default queue_as :high
def perform(conversation, message_params) def perform(conversation, message_params)
conversation.messages.create!(message_params) conversation.messages.create!(message_params)

View File

@@ -1,5 +1,5 @@
class DeleteObjectJob < ApplicationJob class DeleteObjectJob < ApplicationJob
queue_as :default queue_as :low
def perform(object) def perform(object)
object.destroy! object.destroy!

View File

@@ -1,5 +1,5 @@
class EventDispatcherJob < ApplicationJob class EventDispatcherJob < ApplicationJob
queue_as :events queue_as :critical
def perform(event_name, timestamp, data) def perform(event_name, timestamp, data)
Rails.configuration.dispatcher.async_dispatcher.publish_event(event_name, timestamp, data) Rails.configuration.dispatcher.async_dispatcher.publish_event(event_name, timestamp, data)

View File

@@ -1,5 +1,5 @@
class HookJob < ApplicationJob class HookJob < ApplicationJob
queue_as :integrations queue_as :medium
def perform(hook, event_name, event_data = {}) def perform(hook, event_name, event_data = {})
case hook.app_id case hook.app_id

View File

@@ -1,5 +1,5 @@
class Inboxes::FetchImapEmailInboxesJob < ApplicationJob class Inboxes::FetchImapEmailInboxesJob < ApplicationJob
queue_as :low queue_as :scheduled_jobs
def perform def perform
Inbox.where(channel_type: 'Channel::Email').all.find_each(batch_size: 100) do |inbox| Inbox.where(channel_type: 'Channel::Email').all.find_each(batch_size: 100) do |inbox|

View File

@@ -1,7 +1,7 @@
require 'net/imap' require 'net/imap'
class Inboxes::FetchImapEmailsJob < ApplicationJob class Inboxes::FetchImapEmailsJob < ApplicationJob
queue_as :low queue_as :scheduled_jobs
def perform(channel) def perform(channel)
return unless should_fetch_email?(channel) return unless should_fetch_email?(channel)

View File

@@ -1,5 +1,5 @@
class WebhookJob < ApplicationJob class WebhookJob < ApplicationJob
queue_as :webhooks queue_as :medium
def perform(url, payload) def perform(url, payload)
Webhooks::Trigger.execute(url, payload) Webhooks::Trigger.execute(url, payload)

View File

@@ -40,10 +40,10 @@ class CustomAttributeDefinition < ApplicationRecord
private private
def sync_widget_pre_chat_custom_fields def sync_widget_pre_chat_custom_fields
::Inboxes::SyncWidgetPreChatCustomFieldsJob.perform_now(account, attribute_key) ::Inboxes::SyncWidgetPreChatCustomFieldsJob.perform_later(account, attribute_key)
end end
def update_widget_pre_chat_custom_fields def update_widget_pre_chat_custom_fields
::Inboxes::UpdateWidgetPreChatCustomFieldsJob.perform_now(account, self) ::Inboxes::UpdateWidgetPreChatCustomFieldsJob.perform_later(account, self)
end end
end end

View File

@@ -11,23 +11,22 @@
# Sidekiq will run this file through ERB when reading it so you can # Sidekiq will run this file through ERB when reading it so you can
# even put in dynamic logic, like a host-specific queue. # even put in dynamic logic, like a host-specific queue.
# http://www.mikeperham.com/2013/11/13/advanced-sidekiq-host-specific-queues/ # http://www.mikeperham.com/2013/11/13/advanced-sidekiq-host-specific-queues/
# https://github.com/sidekiq/sidekiq/wiki/Advanced-Options
# Since queues are declared without waits, the jobs in lower ranking queues will only be processed
# if there are no jobs in higher ranking queues.
:queues: :queues:
- [async_database_migration, 1] - critical
- [low, 2] - high
- [scheduled_jobs, 2] - medium
- [webhooks, 2] - default
- [bots, 2] - mailers
- [active_storage_analysis, 2] - action_mailbox_routing
- [action_mailbox_incineration, 2] - low
- [active_storage_purge, 2] - scheduled_jobs
- [integrations, 3] - async_database_migration
- [default, 3] - active_storage_analysis
- [mailers, 3] - active_storage_purge
- [medium, 4] - action_mailbox_incineration
- [events, 4]
- [action_mailbox_routing, 4]
- [high, 5]
- [critical, 10]
# you can override concurrency based on environment # you can override concurrency based on environment
production: production:

View File

@@ -11,7 +11,7 @@ RSpec.describe AgentBots::WebhookJob, type: :job do
it 'queues the job' do it 'queues the job' do
expect { job }.to have_enqueued_job(described_class) expect { job }.to have_enqueued_job(described_class)
.with(url, payload) .with(url, payload)
.on_queue('bots') .on_queue('high')
end end
it 'executes perform' do it 'executes perform' do

View File

@@ -17,7 +17,7 @@ RSpec.describe Agents::DestroyJob, type: :job do
it 'enqueues the job' do it 'enqueues the job' do
expect { job }.to have_enqueued_job(described_class) expect { job }.to have_enqueued_job(described_class)
.with(account, user) .with(account, user)
.on_queue('default') .on_queue('low')
end end
describe '#perform' do describe '#perform' do

View File

@@ -6,7 +6,7 @@ RSpec.describe Avatar::AvatarFromUrlJob, type: :job do
it 'enqueues the job' do it 'enqueues the job' do
expect { described_class.perform_later(avatarable, avatar_url) }.to have_enqueued_job(described_class) expect { described_class.perform_later(avatarable, avatar_url) }.to have_enqueued_job(described_class)
.on_queue('default') .on_queue('low')
end end
it 'will attach avatar from url' do it 'will attach avatar from url' do

View File

@@ -8,7 +8,7 @@ RSpec.describe DeleteObjectJob, type: :job do
it 'enqueues the job' do it 'enqueues the job' do
expect { job }.to have_enqueued_job(described_class) expect { job }.to have_enqueued_job(described_class)
.with(account) .with(account)
.on_queue('default') .on_queue('low')
end end
context 'when an object is passed to the job' do context 'when an object is passed to the job' do

View File

@@ -11,7 +11,7 @@ RSpec.describe EventDispatcherJob, type: :job do
it 'queues the job' do it 'queues the job' do
expect { job }.to have_enqueued_job(described_class) expect { job }.to have_enqueued_job(described_class)
.with(event_name, timestamp, event_data) .with(event_name, timestamp, event_data)
.on_queue('events') .on_queue('critical')
end end
it 'publishes event' do it 'publishes event' do

View File

@@ -12,7 +12,7 @@ RSpec.describe HookJob, type: :job do
it 'enqueues the job' do it 'enqueues the job' do
expect { job }.to have_enqueued_job(described_class) expect { job }.to have_enqueued_job(described_class)
.with(hook, event_name, event_data) .with(hook, event_name, event_data)
.on_queue('integrations') .on_queue('medium')
end end
context 'when handleable events like message.created' do context 'when handleable events like message.created' do

View File

@@ -10,7 +10,7 @@ RSpec.describe Inboxes::FetchImapEmailInboxesJob, type: :job do
it 'enqueues the job' do it 'enqueues the job' do
expect { described_class.perform_later }.to have_enqueued_job(described_class) expect { described_class.perform_later }.to have_enqueued_job(described_class)
.on_queue('low') .on_queue('scheduled_jobs')
end end
context 'when called' do context 'when called' do

View File

@@ -19,7 +19,7 @@ RSpec.describe Inboxes::FetchImapEmailsJob, type: :job do
it 'enqueues the job' do it 'enqueues the job' do
expect { described_class.perform_later }.to have_enqueued_job(described_class) expect { described_class.perform_later }.to have_enqueued_job(described_class)
.on_queue('low') .on_queue('scheduled_jobs')
end end
context 'when imap fetch new emails' do context 'when imap fetch new emails' do

View File

@@ -11,7 +11,7 @@ RSpec.describe WebhookJob, type: :job do
it 'queues the job' do it 'queues the job' do
expect { job }.to have_enqueued_job(described_class) expect { job }.to have_enqueued_job(described_class)
.with(url, payload) .with(url, payload)
.on_queue('webhooks') .on_queue('medium')
end end
it 'executes perform' do it 'executes perform' do