events: fix MonitoredTasks' save_on_success not behaving as expected

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-08-23 19:13:41 +02:00
parent 917c4ae835
commit 649835cc61

View file

@ -134,10 +134,13 @@ class MonitoredTask(Task):
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments
def after_return(self, status, retval, task_id, args: list[Any], kwargs: dict[str, Any], einfo): def after_return(self, status, retval, task_id, args: list[Any], kwargs: dict[str, Any], einfo):
if self._result: super().after_return(status, retval, task_id, args, kwargs, einfo=einfo)
if not self._result:
return
if not self._result.uid: if not self._result.uid:
self._result.uid = self._uid self._result.uid = self._uid
if self.save_on_success: if self._result.status == TaskResultStatus.SUCCESSFUL and not self.save_on_success:
return
TaskInfo( TaskInfo(
task_name=self.__name__, task_name=self.__name__,
task_description=self.__doc__, task_description=self.__doc__,
@ -150,10 +153,10 @@ class MonitoredTask(Task):
task_call_args=args, task_call_args=args,
task_call_kwargs=kwargs, task_call_kwargs=kwargs,
).save(self.result_timeout_hours) ).save(self.result_timeout_hours)
return super().after_return(status, retval, task_id, args, kwargs, einfo=einfo)
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments
def on_failure(self, exc, task_id, args, kwargs, einfo): def on_failure(self, exc, task_id, args, kwargs, einfo):
super().on_failure(exc, task_id, args, kwargs, einfo=einfo)
if not self._result: if not self._result:
self._result = TaskResult(status=TaskResultStatus.ERROR, messages=[str(exc)]) self._result = TaskResult(status=TaskResultStatus.ERROR, messages=[str(exc)])
if not self._result.uid: if not self._result.uid:
@ -174,7 +177,6 @@ class MonitoredTask(Task):
EventAction.SYSTEM_TASK_EXCEPTION, EventAction.SYSTEM_TASK_EXCEPTION,
message=(f"Task {self.__name__} encountered an error: {exception_to_string(exc)}"), message=(f"Task {self.__name__} encountered an error: {exception_to_string(exc)}"),
).save() ).save()
return super().on_failure(exc, task_id, args, kwargs, einfo=einfo)
def run(self, *args, **kwargs): def run(self, *args, **kwargs):
raise NotImplementedError raise NotImplementedError