Skip to content

Commit

Permalink
only fire one SSE per update to an Incident
Browse files Browse the repository at this point in the history
See this issue for more context:
#1369
  • Loading branch information
srabraham committed Nov 5, 2024
1 parent c771ac4 commit a8807cd
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/ims/store/_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,6 @@ def _attachRangeHandlesToIncident(
self._log.info(
"Attached Rangers {rangerHandles} to incident "
"{eventID}#{incidentNumber}",
storeWriteClass=Incident,
eventID=eventID,
incidentNumber=incidentNumber,
rangerHandles=rangerHandles,
Expand Down Expand Up @@ -859,7 +858,6 @@ def _attachIncidentTypesToIncident(
self._log.info(
"Attached incident types {incidentTypes} to incident "
"{eventID}#{incidentNumber}",
storeWriteClass=Incident,
eventID=eventID,
incidentNumber=incidentNumber,
incidentTypes=incidentTypes,
Expand All @@ -884,6 +882,19 @@ def _createReportEntry(
reportEntry=reportEntry,
)

def _notifyIncidentUpdate(
self,
eventID: str,
incidentNumber: int,
) -> None:
# This will trigger the DataStoreEventSourceLogObserver
self._log.info(
"Firing incident update event for {eventID}#{incidentNumber}",
storeWriteClass=Incident,
eventID=eventID,
incidentNumber=incidentNumber,
)

def _createAndAttachReportEntriesToIncident(
self,
eventID: str,
Expand All @@ -909,7 +920,6 @@ def _createAndAttachReportEntriesToIncident(
self._log.info(
"Attached report entries to incident {eventID}#{incidentNumber}: "
"{reportEntries}",
storeWriteClass=Incident,
eventID=eventID,
incidentNumber=incidentNumber,
reportEntries=reportEntries,
Expand Down Expand Up @@ -1082,10 +1092,11 @@ def createIncident(

self._log.info(
"Created incident {incident}",
storeWriteClass=Incident,
incident=incident,
)

self._notifyIncidentUpdate(incident.eventID, incident.number)

return incident

async def createIncident(self, incident: Incident, author: str) -> Incident:
Expand Down Expand Up @@ -1148,7 +1159,6 @@ def setIncidentAttribute(txn: Transaction) -> None:
self._log.info(
"{author} updated incident {eventID}#{incidentNumber}: "
"{attribute}={value}",
storeWriteClass=Incident,
query=query,
eventID=eventID,
incidentNumber=incidentNumber,
Expand All @@ -1157,6 +1167,8 @@ def setIncidentAttribute(txn: Transaction) -> None:
author=author,
)

self._notifyIncidentUpdate(eventID, incidentNumber)

async def setIncident_priority(
self,
eventID: str,
Expand Down Expand Up @@ -1336,13 +1348,14 @@ def setIncident_rangers(txn: Transaction) -> None:
self._log.info(
"{author} set Rangers for incident {eventID}#{incidentNumber}: "
"{rangerHandles}",
storeWriteClass=Incident,
author=author,
eventID=eventID,
incidentNumber=incidentNumber,
rangerHandles=rangerHandles,
)

self._notifyIncidentUpdate(eventID, incidentNumber)

async def setIncident_incidentTypes(
self,
eventID: str,
Expand Down Expand Up @@ -1395,13 +1408,14 @@ def setIncident_incidentTypes(txn: Transaction) -> None:
self._log.info(
"{author} set incident types for incident "
"{eventID}#{incidentNumber}: {incidentTypes}",
storeWriteClass=Incident,
author=author,
eventID=eventID,
incidentNumber=incidentNumber,
incidentTypes=incidentTypes,
)

self._notifyIncidentUpdate(eventID, incidentNumber)

async def addReportEntriesToIncident(
self,
eventID: str,
Expand Down Expand Up @@ -1446,6 +1460,8 @@ def addReportEntriesToIncident(txn: Transaction) -> None:
)
raise

self._notifyIncidentUpdate(eventID, incidentNumber)

###
# Incident Reports
###
Expand Down

0 comments on commit a8807cd

Please sign in to comment.