Skip to content

Add run notifications option to run.init #705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions simvue/api/objects/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,16 @@ def heartbeat_timeout(self, time_seconds: int | None) -> None:

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

@notifications.setter
@write_only
@pydantic.validate_call
def notifications(self, notifications: typing.Literal["none", "email"]) -> None:
self._staging["notifications"] = notifications
def notifications(
self, notifications: typing.Literal["none", "all", "error", "lost"]
) -> None:
self._staging["notifications"] = {"state": notifications}

@property
@staging_check
Expand Down
7 changes: 6 additions & 1 deletion simvue/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def _start(self, reconnect: bool = False) -> bool:

logger.debug("Starting run")

if self._sv_obj:
if self._sv_obj and self._sv_obj.status != "running":
self._sv_obj.status = self._status
self._sv_obj.commit()

Expand Down Expand Up @@ -565,6 +565,7 @@ def init(
folder: typing.Annotated[
str, pydantic.Field(None, pattern=FOLDER_REGEX)
] = None,
notification: typing.Literal["none", "all", "error", "lost"] = "none",
running: bool = True,
retention_period: str | None = None,
timeout: int | None = 180,
Expand All @@ -586,6 +587,9 @@ def init(
description of the run, by default None
folder : str, optional
folder within which to store the run, by default "/"
notification: typing.Literal["none", "all", "error", "lost"], optional
whether to notify the user by email upon completion of the run if
the run is in the specified state, by default "none"
running : bool, optional
whether to set the status as running or created, the latter implying
the run will be commenced at a later time. Default is True.
Expand Down Expand Up @@ -686,6 +690,7 @@ def init(
self._sv_obj.tags = tags
self._sv_obj.metadata = (metadata or {}) | git_info(os.getcwd()) | environment()
self._sv_obj.heartbeat_timeout = timeout
self._sv_obj.notifications = notification

if self._status == "running":
self._sv_obj.system = get_system()
Expand Down
Loading