events: fix MonitoredTasks' save_on_success not behaving as expected
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
917c4ae835
commit
649835cc61
|
@ -134,26 +134,29 @@ 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.uid:
|
if not self._result:
|
||||||
self._result.uid = self._uid
|
return
|
||||||
if self.save_on_success:
|
if not self._result.uid:
|
||||||
TaskInfo(
|
self._result.uid = self._uid
|
||||||
task_name=self.__name__,
|
if self._result.status == TaskResultStatus.SUCCESSFUL and not self.save_on_success:
|
||||||
task_description=self.__doc__,
|
return
|
||||||
start_timestamp=self.start,
|
TaskInfo(
|
||||||
finish_timestamp=default_timer(),
|
task_name=self.__name__,
|
||||||
finish_time=datetime.now(),
|
task_description=self.__doc__,
|
||||||
result=self._result,
|
start_timestamp=self.start,
|
||||||
task_call_module=self.__module__,
|
finish_timestamp=default_timer(),
|
||||||
task_call_func=self.__name__,
|
finish_time=datetime.now(),
|
||||||
task_call_args=args,
|
result=self._result,
|
||||||
task_call_kwargs=kwargs,
|
task_call_module=self.__module__,
|
||||||
).save(self.result_timeout_hours)
|
task_call_func=self.__name__,
|
||||||
return super().after_return(status, retval, task_id, args, kwargs, einfo=einfo)
|
task_call_args=args,
|
||||||
|
task_call_kwargs=kwargs,
|
||||||
|
).save(self.result_timeout_hours)
|
||||||
|
|
||||||
# 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
|
||||||
|
|
Reference in New Issue