events: ensure fallback result is set for on_failure
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
e5b63377a0
commit
f933cd99ad
|
@ -138,25 +138,30 @@ class MonitoredTask(Task):
|
||||||
def after_return(
|
def after_return(
|
||||||
self, status, retval, task_id, args: list[Any], kwargs: dict[str, Any], einfo
|
self, status, retval, task_id, args: list[Any], kwargs: dict[str, Any], einfo
|
||||||
):
|
):
|
||||||
if not self._result.uid:
|
if self._result:
|
||||||
self._result.uid = self._uid
|
if not self._result.uid:
|
||||||
if self.save_on_success and self._result:
|
self._result.uid = self._uid
|
||||||
TaskInfo(
|
if self.save_on_success:
|
||||||
task_name=self.__name__,
|
TaskInfo(
|
||||||
task_description=self.__doc__,
|
task_name=self.__name__,
|
||||||
start_timestamp=self.start,
|
task_description=self.__doc__,
|
||||||
finish_timestamp=default_timer(),
|
start_timestamp=self.start,
|
||||||
finish_time=datetime.now(),
|
finish_timestamp=default_timer(),
|
||||||
result=self._result,
|
finish_time=datetime.now(),
|
||||||
task_call_module=self.__module__,
|
result=self._result,
|
||||||
task_call_func=self.__name__,
|
task_call_module=self.__module__,
|
||||||
task_call_args=args,
|
task_call_func=self.__name__,
|
||||||
task_call_kwargs=kwargs,
|
task_call_args=args,
|
||||||
).save(self.result_timeout_hours)
|
task_call_kwargs=kwargs,
|
||||||
|
).save(self.result_timeout_hours)
|
||||||
return super().after_return(status, retval, task_id, args, kwargs, einfo=einfo)
|
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):
|
||||||
|
if not self._result:
|
||||||
|
self._result = TaskResult(
|
||||||
|
status=TaskResultStatus.ERROR, messages=[str(exc)]
|
||||||
|
)
|
||||||
if not self._result.uid:
|
if not self._result.uid:
|
||||||
self._result.uid = self._uid
|
self._result.uid = self._uid
|
||||||
TaskInfo(
|
TaskInfo(
|
||||||
|
|
Reference in New Issue