Skip to content

Commit

Permalink
feat(perf): sla-9 improve perf of TriggerSlasForAccountsJob (#8953)
Browse files Browse the repository at this point in the history
* feat: improve perf of TriggerSlasForAccountsJob
  • Loading branch information
vishnu-narayanan committed Feb 20, 2024
1 parent e6cf8c3 commit f92cea1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion enterprise/app/jobs/sla/trigger_slas_for_accounts_job.rb
Expand Up @@ -2,7 +2,7 @@ class Sla::TriggerSlasForAccountsJob < ApplicationJob
queue_as :scheduled_jobs

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}"
Sla::ProcessAccountAppliedSlasJob.perform_later(account)
end
Expand Down
17 changes: 13 additions & 4 deletions spec/enterprise/jobs/sla/trigger_slas_for_accounts_job_spec.rb
@@ -1,16 +1,25 @@
require 'rails_helper'

RSpec.describe Sla::TriggerSlasForAccountsJob 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
expect { described_class.perform_later }.to have_enqueued_job(described_class)
.on_queue('scheduled_jobs')
end

it 'calls the ProcessAccountAppliedSlasJob' do
expect(Sla::ProcessAccountAppliedSlasJob).to receive(:perform_later).with(account).and_call_original
it 'calls the ProcessAccountAppliedSlasJob for accounts with SLA' do
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
end
end
Expand Down

0 comments on commit f92cea1

Please sign in to comment.