feat(perf): sla-9 improve perf of TriggerSlasForAccountsJob (#8953)
* feat: improve perf of TriggerSlasForAccountsJob
This commit is contained in:
@@ -2,7 +2,7 @@ class Sla::TriggerSlasForAccountsJob < ApplicationJob
|
|||||||
queue_as :scheduled_jobs
|
queue_as :scheduled_jobs
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
Account.find_each do |account|
|
Account.joins(:sla_policies).distinct.find_each do |account|
|
||||||
Rails.logger.info "Enqueuing ProcessAccountAppliedSlasJob for account #{account.id}"
|
Rails.logger.info "Enqueuing ProcessAccountAppliedSlasJob for account #{account.id}"
|
||||||
Sla::ProcessAccountAppliedSlasJob.perform_later(account)
|
Sla::ProcessAccountAppliedSlasJob.perform_later(account)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,16 +1,25 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Sla::TriggerSlasForAccountsJob do
|
RSpec.describe Sla::TriggerSlasForAccountsJob do
|
||||||
context 'when perform is called' do
|
context 'when perform is called' do
|
||||||
let(:account) { create(:account) }
|
let(:account_with_sla) { create(:account) }
|
||||||
|
let(:account_without_sla) { create(:account) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
create(:sla_policy, account: account_with_sla)
|
||||||
|
end
|
||||||
|
|
||||||
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('scheduled_jobs')
|
.on_queue('scheduled_jobs')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'calls the ProcessAccountAppliedSlasJob' do
|
it 'calls the ProcessAccountAppliedSlasJob for accounts with SLA' do
|
||||||
expect(Sla::ProcessAccountAppliedSlasJob).to receive(:perform_later).with(account).and_call_original
|
expect(Sla::ProcessAccountAppliedSlasJob).to receive(:perform_later).with(account_with_sla).and_call_original
|
||||||
|
described_class.perform_now
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not call the ProcessAccountAppliedSlasJob for accounts without SLA' do
|
||||||
|
expect(Sla::ProcessAccountAppliedSlasJob).not_to receive(:perform_later).with(account_without_sla)
|
||||||
described_class.perform_now
|
described_class.perform_now
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user