Skip to content
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
1 change: 1 addition & 0 deletions simvue/api/objects/alert/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, identifier: str | None = None, **kwargs) -> None:
"""Retrieve an alert from the Simvue server by identifier"""
self._label = "alert"
super().__init__(identifier=identifier, **kwargs)
self._local_only_args = ["frequency", "pattern", "aggregation"]

def compare(self, other: "AlertBase") -> bool:
"""Compare this alert to another"""
Expand Down
13 changes: 13 additions & 0 deletions simvue/api/objects/alert/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def __init__(self, identifier: str | None = None, **kwargs) -> None:
"""Connect to a local or remote threshold alert by identifier"""
self.alert = MetricThresholdAlertDefinition(self)
super().__init__(identifier, **kwargs)
self._local_only_args += [
"rule",
"window",
"metric",
"threshold",
]

@classmethod
def get(
Expand Down Expand Up @@ -117,6 +123,13 @@ def __init__(self, identifier: str | None = None, **kwargs) -> None:
"""Connect to a local or remote threshold alert by identifier"""
self.alert = MetricRangeAlertDefinition(self)
super().__init__(identifier, **kwargs)
self._local_only_args += [
"rule",
"window",
"metric",
"range_low",
"range_high",
]

def compare(self, other: "MetricsRangeAlert") -> bool:
"""Compare two MetricRangeAlerts"""
Expand Down
1 change: 1 addition & 0 deletions simvue/api/objects/artifact/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def __init__(
self._label = "artifact"
self._endpoint = f"{self._label}s"
super().__init__(identifier=identifier, _read_only=_read_only, **kwargs)
self._local_only_args += ["storage", "file_path", "runs"]

# If the artifact is an online instance, need a place to store the response
# from the initial creation
Expand Down
15 changes: 15 additions & 0 deletions simvue/api/objects/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ def __init__(
self._read_only: bool = _read_only
self._is_set: bool = False
self._endpoint: str = getattr(self, "_endpoint", f"{self._label}s")

# For simvue object initialisation, unlike the server there is no nested
# arguments, however this means that there are extra keys during post which
# need removing, this attribute handles that and should be set in subclasses.
self._local_only_args: list[str] = []

self._identifier: str | None = (
identifier if identifier is not None else f"offline_{uuid.uuid1()}"
)
Expand Down Expand Up @@ -633,6 +639,10 @@ def _post_single(
if not is_json:
kwargs = msgpack.packb(data or kwargs, use_bin_type=True)

# Remove any extra keys
for key in self._local_only_args:
_ = (data or kwargs).pop(key, None)

_response = sv_post(
url=f"{self._base_url}",
headers=self._headers | {"Content-Type": "application/msgpack"},
Expand Down Expand Up @@ -670,6 +680,11 @@ def _post_single(
def _put(self, **kwargs) -> dict[str, typing.Any]:
if not self.url:
raise RuntimeError(f"Identifier for instance of {self._label} Unknown")

# Remove any extra keys
for key in self._local_only_args:
_ = kwargs.pop(key, None)

_response = sv_put(
url=f"{self.url}", headers=self._headers, data=kwargs, is_json=True
)
Expand Down
1 change: 0 additions & 1 deletion simvue/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,6 @@ def init(
self._sv_obj.alerts = []
self._sv_obj.created = time.time()
self._sv_obj.notifications = notification
self._sv_obj._staging["folder_id"] = self._folder.id

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