Skip to content

Commit 5b03403

Browse files
committed
Return alert ID after creation
1 parent dca1974 commit 5b03403

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

simvue/run.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ def add_alerts(
13091309
return False
13101310

13111311
@pydantic.validate_call
1312-
@skip_if_failed("_aborted", "_suppress_errors", False)
1312+
@skip_if_failed("_aborted", "_suppress_errors", None)
13131313
@pydantic.validate_call
13141314
def create_alert(
13151315
self,
@@ -1332,7 +1332,7 @@ def create_alert(
13321332
] = "average",
13331333
notification: typing.Literal["email", "none"] = "none",
13341334
pattern: typing.Optional[str] = None,
1335-
) -> bool:
1335+
) -> typing.Optional[str]:
13361336
"""Creates an alert with the specified name (if it doesn't exist)
13371337
and applies it to the current run. If alert already exists it will
13381338
not be duplicated.
@@ -1394,27 +1394,27 @@ def create_alert(
13941394
13951395
Returns
13961396
-------
1397-
bool
1398-
returns True on success
1397+
str | None
1398+
returns the created alert ID if successful
13991399
"""
14001400
if self._mode == "disabled":
1401-
return True
1401+
return None
14021402

14031403
if not self._simvue:
14041404
self._error("Cannot add alert, run not initialised")
1405-
return False
1405+
return None
14061406

14071407
if rule in ("is below", "is above") and threshold is None:
14081408
self._error("threshold must be defined for the specified alert type")
1409-
return False
1409+
return None
14101410

14111411
if rule in ("is outside range", "is inside range") and (
14121412
range_low is None or range_high is None
14131413
):
14141414
self._error(
14151415
"range_low and range_high must be defined for the specified alert type"
14161416
)
1417-
return False
1417+
return None
14181418

14191419
alert_definition = {}
14201420

@@ -1461,15 +1461,14 @@ def create_alert(
14611461
alert_id = response["id"]
14621462
else:
14631463
self._error("unable to create alert")
1464-
return False
1464+
return None
14651465

14661466
if alert_id:
14671467
# TODO: What if we keep existing alerts/add a new one later?
14681468
data = {"id": self._id, "alerts": [alert_id]}
1469-
if self._simvue.update(data):
1470-
return True
1469+
self._simvue.update(data)
14711470

1472-
return False
1471+
return alert_id
14731472

14741473
@pydantic.validate_call
14751474
@skip_if_failed("_aborted", "_suppress_errors", False)

0 commit comments

Comments
 (0)