diff --git a/simvue/api/objects/alert/user.py b/simvue/api/objects/alert/user.py index e4787e74..5c43febb 100644 --- a/simvue/api/objects/alert/user.py +++ b/simvue/api/objects/alert/user.py @@ -101,7 +101,7 @@ def new( token for alternative server, default None """ - return cls( + _alert = cls( name=name, description=description, notification=notification, @@ -109,10 +109,11 @@ def new( enabled=enabled, server_url=server_url, server_token=server_token, - _params={"deduplicate": True}, _read_only=False, _offline=offline, ) + _alert._params = {"deduplicate": True} + return _alert @override def _compare_objects(self, other: "AlertBase") -> bool: diff --git a/simvue/run.py b/simvue/run.py index 0c3cd77a..73165c7a 100644 --- a/simvue/run.py +++ b/simvue/run.py @@ -76,9 +76,6 @@ except ImportError: from typing_extensions import Self -if typing.TYPE_CHECKING: - from simvue.api.objects.alert.base import AlertBase - HEARTBEAT_INTERVAL: int = 60 RESOURCES_METRIC_PREFIX: str = "resources" @@ -2317,18 +2314,6 @@ def add_alerts( return True - def _check_if_alert_exists(self, alert: "AlertBase") -> str | None: - """Check if an existing alert matches definition.""" - # If the alert already exists just add the existing one - for _id, _existing_alert in Alert.get( - offline=self.mode == "offline", - server_url=self._user_config.server.url, - server_token=self._user_config.server.token, - ): - if _existing_alert == alert: - return _id - return None - @skip_if_failed("_aborted", "_suppress_errors", on_failure_return=None) @pydantic.validate_call def create_metric_range_alert( @@ -2413,12 +2398,6 @@ def create_metric_range_alert( server_token=self._user_config.server.token, ) - # If the alert already exists just add the existing one - if _existing_id := self._check_if_alert_exists(_alert): - if attach_to_run: - self.add_alerts(ids=[_existing_id]) - return _existing_id - _alert.abort = trigger_abort _alert.commit() if attach_to_run: @@ -2506,12 +2485,6 @@ def create_metric_threshold_alert( server_token=self._user_config.server.token, ) - # If the alert already exists just add the existing one - if _existing_id := self._check_if_alert_exists(_alert): - if attach_to_run: - self.add_alerts(ids=[_existing_id]) - return _existing_id - _alert.abort = trigger_abort _alert.commit() if attach_to_run: @@ -2571,12 +2544,6 @@ def create_event_alert( server_token=self._user_config.server.token, ) - # If the alert already exists just add the existing one - if _existing_id := self._check_if_alert_exists(_alert): - if attach_to_run: - self.add_alerts(ids=[_existing_id]) - return _existing_id - _alert.abort = trigger_abort _alert.commit() @@ -2630,12 +2597,6 @@ def create_user_alert( server_token=self._user_config.server.token, ) - # If the alert already exists just add the existing one - if _existing_id := self._check_if_alert_exists(_alert): - if attach_to_run: - self.add_alerts(ids=[_existing_id]) - return _existing_id - _alert.abort = trigger_abort _alert.commit() if attach_to_run: