Commit db3f0ce4 authored by James Fargher's avatar James Fargher

Merge branch 'sy-dont-raise-from-escalation-workers' into 'master'

Gracefully exit from escalation workers on failure

See merge request gitlab-org/gitlab!66292
parents fa74a193 bb3340cc
......@@ -13,7 +13,8 @@ module IncidentManagement
feature_category :incident_management
def perform(escalation_id)
escalation = IncidentManagement::PendingEscalations::Alert.find(escalation_id)
escalation = IncidentManagement::PendingEscalations::Alert.find_by_id(escalation_id)
return unless escalation
IncidentManagement::PendingEscalations::ProcessService.new(escalation).execute
end
......
......@@ -13,7 +13,8 @@ module IncidentManagement
feature_category :incident_management
def perform(alert_id)
alert = ::AlertManagement::Alert.find(alert_id)
alert = ::AlertManagement::Alert.find_by_id(alert_id)
return unless alert
::IncidentManagement::PendingEscalations::CreateService.new(alert).execute
end
......
......@@ -8,14 +8,27 @@ RSpec.describe IncidentManagement::PendingEscalations::AlertCheckWorker do
let_it_be(:escalation) { create(:incident_management_pending_alert_escalation) }
describe '#perform' do
subject { worker.perform(escalation.id) }
subject { worker.perform(*args) }
it 'processes the escalation' do
process_service = spy(IncidentManagement::PendingEscalations::ProcessService)
context 'with valid escalation' do
let(:args) { [escalation.id.to_s] }
expect(IncidentManagement::PendingEscalations::ProcessService).to receive(:new).with(escalation).and_return(process_service)
subject
expect(process_service).to have_received(:execute)
it 'processes the escalation' do
expect_next_instance_of(IncidentManagement::PendingEscalations::ProcessService, escalation) do |service|
expect(service).to receive(:execute)
end
subject
end
end
context 'without valid escalation' do
let(:args) { [non_existing_record_id] }
it 'does nothing' do
expect(IncidentManagement::PendingEscalations::CreateService).not_to receive(:new)
expect { subject }.not_to raise_error
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe IncidentManagement::PendingEscalations::AlertCreateWorker do
let(:worker) { described_class.new }
let_it_be(:alert) { create(:alert_management_alert) }
describe '#perform' do
subject { worker.perform(*args) }
context 'with valid alert' do
let(:args) { [alert.id.to_s] }
it 'processes the escalation' do
expect_next_instance_of(IncidentManagement::PendingEscalations::CreateService, alert) do |service|
expect(service).to receive(:execute)
end
subject
end
end
context 'without valid alert' do
let(:args) { [non_existing_record_id] }
it 'does nothing' do
expect(IncidentManagement::PendingEscalations::CreateService).not_to receive(:new)
expect { subject }.not_to raise_error
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment