events: ensure fallback result is set for on_failure

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-07-30 09:36:09 +02:00
parent fb6e8ca1eb
commit a4fd58a0db
1 changed files with 20 additions and 15 deletions

View File

@ -138,9 +138,10 @@ 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 self._result:
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 and self._result: if self.save_on_success:
TaskInfo( TaskInfo(
task_name=self.__name__, task_name=self.__name__,
task_description=self.__doc__, task_description=self.__doc__,
@ -157,6 +158,10 @@ class MonitoredTask(Task):
# 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(