Skip to content

Commit

Permalink
Bugfix/do not overwrite stable at (#4304)
Browse files Browse the repository at this point in the history
* Fixes race condition where the updated incident is marked as stable, but the update flow has not yet completed.

* Reduces likelihood of incident_update_flow() running before incident_service.update() completes.

* Adds a check to only set the stable at field if the incident is not active and the stable_at field has not been set yet.

* Restores previous version of incident update functions

* Do not overwrite the incident stable_at field when calculating incident costs.

* Default participant_role_renounced_at is set to utcnow
  • Loading branch information
metroid-samus authored Jan 29, 2024
1 parent 836cac5 commit af11f01
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/dispatch/incident_cost/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,22 +214,18 @@ def calculate_incident_response_cost_with_classic_model(incident: Incident, inci
continue

participant_role_assumed_at = participant_role.assumed_at
# we set the renounced_at default time to the current time
participant_role_renounced_at = datetime.utcnow()

if incident.status == IncidentStatus.active:
# we set the renounced_at default time to the current time
participant_role_renounced_at = datetime.utcnow()

if participant_role.renounced_at:
# the participant left the conversation or got assigned another role
# we use the role's renounced_at time
participant_role_renounced_at = participant_role.renounced_at
else:
# Fixes race condition where the updated incident is marked as stable, but the update flow has not yet completed.
if not incident.stable_at:
incident.stable_at = datetime.utcnow()

# we set the renounced_at default time to the stable_at time
participant_role_renounced_at = incident.stable_at
# we set the renounced_at default time to the stable_at time if the stable_at time exists
if incident.stable_at:
participant_role_renounced_at = incident.stable_at

if participant_role.renounced_at:
# the participant left the conversation or got assigned another role
Expand Down

0 comments on commit af11f01

Please sign in to comment.