Prevent errors for conflicting pending escalations
What does this MR do and why?
- Resolves uncaught
Rule has already been taken
error when an escalatable is queued for escalation multiple times. - Makes the
{Alert/Issue}CreateWorkers
actually idempotent.
How to set up and validate locally
- Open a project for which you have maintainer permissions (ids needed for command below)
- Create an escalation policy (
project > Monitor > Escalation Policies
) with multiple rules: - Create an incident & trigger escalations
user = User.first # your user project = Project.find(21) # your project incident = IncidentManagement::Incidents::CreateService.new(project, user, title: 'incident title', description: 'description').execute[:issue] IncidentManagement::PendingEscalations::CreateService.new(incident.escalation_status).execute # => Should return an array of strings with as many elements as escalation rules you configured; escalations were created!
- Before the 2nd escalation rule fires, queue escalations again
IncidentManagement::PendingEscalations::CreateService.new(incident.escalation_status).execute # => Should return nil; escalations should not be created
BEFORE
If you ran the above code on master, the last step would result in an error:
IncidentManagement::PendingEscalations::CreateService.new(incident.escalation_status).execute
# => ActiveRecord::RecordInvalid: Validation failed: Rule has already been taken
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #372194 (closed)
Edited by Sarah Yasonik