Skip to content

Commit 9531b62

Browse files
authored
Merge pull request #705 from simvue-io/wk9874/run_notifications
Add run notifications option to run.init
2 parents d25345a + 01c9b9d commit 9531b62

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

simvue/api/objects/run.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,16 @@ def heartbeat_timeout(self, time_seconds: int | None) -> None:
214214

215215
@property
216216
@staging_check
217-
def notifications(self) -> typing.Literal["none", "email"]:
218-
return self._get_attribute("notifications")
217+
def notifications(self) -> typing.Literal["none", "all", "error", "lost"]:
218+
return self._get_attribute("notifications")["state"]
219219

220220
@notifications.setter
221221
@write_only
222222
@pydantic.validate_call
223-
def notifications(self, notifications: typing.Literal["none", "email"]) -> None:
224-
self._staging["notifications"] = notifications
223+
def notifications(
224+
self, notifications: typing.Literal["none", "all", "error", "lost"]
225+
) -> None:
226+
self._staging["notifications"] = {"state": notifications}
225227

226228
@property
227229
@staging_check

simvue/run.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def _start(self, reconnect: bool = False) -> bool:
465465

466466
logger.debug("Starting run")
467467

468-
if self._sv_obj:
468+
if self._sv_obj and self._sv_obj.status != "running":
469469
self._sv_obj.status = self._status
470470
self._sv_obj.commit()
471471

@@ -565,6 +565,7 @@ def init(
565565
folder: typing.Annotated[
566566
str, pydantic.Field(None, pattern=FOLDER_REGEX)
567567
] = None,
568+
notification: typing.Literal["none", "all", "error", "lost"] = "none",
568569
running: bool = True,
569570
retention_period: str | None = None,
570571
timeout: int | None = 180,
@@ -586,6 +587,9 @@ def init(
586587
description of the run, by default None
587588
folder : str, optional
588589
folder within which to store the run, by default "/"
590+
notification: typing.Literal["none", "all", "error", "lost"], optional
591+
whether to notify the user by email upon completion of the run if
592+
the run is in the specified state, by default "none"
589593
running : bool, optional
590594
whether to set the status as running or created, the latter implying
591595
the run will be commenced at a later time. Default is True.
@@ -686,6 +690,7 @@ def init(
686690
self._sv_obj.tags = tags
687691
self._sv_obj.metadata = (metadata or {}) | git_info(os.getcwd()) | environment()
688692
self._sv_obj.heartbeat_timeout = timeout
693+
self._sv_obj.notifications = notification
689694

690695
if self._status == "running":
691696
self._sv_obj.system = get_system()

0 commit comments

Comments
 (0)