refactor: perform SLA evaluation directly instead of queueing it

This commit is contained in:
Shivam Mishra
2024-04-08 15:55:20 +05:30
parent aef4b582db
commit bb6cd13110
4 changed files with 7 additions and 32 deletions
@@ -3,7 +3,7 @@ class Sla::ProcessAccountAppliedSlasJob < ApplicationJob
def perform(account)
account.applied_slas.where(sla_status: %w[active active_with_misses]).each do |applied_sla|
Sla::ProcessAppliedSlaJob.perform_later(applied_sla)
Sla::EvaluateAppliedSlaService.new(applied_sla: applied_sla).perform
end
end
end
@@ -1,7 +0,0 @@
class Sla::ProcessAppliedSlaJob < ApplicationJob
queue_as :medium
def perform(applied_sla)
Sla::EvaluateAppliedSlaService.new(applied_sla: applied_sla).perform
end
end
@@ -14,15 +14,15 @@ RSpec.describe Sla::ProcessAccountAppliedSlasJob do
.on_queue('medium')
end
it 'calls the ProcessAppliedSlaJob for both active and active_with_misses' do
expect(Sla::ProcessAppliedSlaJob).to receive(:perform_later).with(active_with_misses_applied_sla).and_call_original
expect(Sla::ProcessAppliedSlaJob).to receive(:perform_later).with(applied_sla).and_call_original
it 'calls the EvaluateAppliedSlaService for both active and active_with_misses' do
expect(Sla::EvaluateAppliedSlaService).to receive(:perform).with(active_with_misses_applied_sla).and_call_original
expect(Sla::EvaluateAppliedSlaService).to receive(:perform).with(applied_sla).and_call_original
described_class.perform_now(account)
end
it 'does not call the ProcessAppliedSlaJob for applied slas that are hit or miss' do
expect(Sla::ProcessAppliedSlaJob).not_to receive(:perform_later).with(hit_applied_sla)
expect(Sla::ProcessAppliedSlaJob).not_to receive(:perform_later).with(miss_applied_sla)
it 'does not call the EvaluateAppliedSlaService for applied slas that are hit or miss' do
expect(Sla::EvaluateAppliedSlaService).not_to receive(:perform).with(hit_applied_sla)
expect(Sla::EvaluateAppliedSlaService).not_to receive(:perform).with(miss_applied_sla)
described_class.perform_now(account)
end
end
@@ -1,18 +0,0 @@
require 'rails_helper'
RSpec.describe Sla::ProcessAppliedSlaJob do
context 'when perform is called' do
let(:account) { create(:account) }
it 'enqueues the job' do
expect { described_class.perform_later }.to have_enqueued_job(described_class)
.on_queue('medium')
end
it 'calls the EvaluateAppliedSlaService' do
applied_sla = create(:applied_sla)
expect(Sla::EvaluateAppliedSlaService).to receive(:new).with(applied_sla: applied_sla).and_call_original
described_class.perform_now(applied_sla)
end
end
end