*: Improve MonitoredTasks' error capture

This commit is contained in:
Jens Langhammer
2020-10-16 16:00:24 +02:00
parent bdc019c7cf
commit 2339e855bb
5 changed files with 11 additions and 6 deletions

View File

@ -2,6 +2,7 @@
from dataclasses import dataclass, field
from datetime import datetime
from enum import Enum
from traceback import format_tb
from typing import Any, Dict, List, Optional
from celery import Task
@ -25,11 +26,15 @@ class TaskResult:
messages: List[str] = field(default_factory=list)
error: Optional[Exception] = field(default=None)
# Optional UID used in cache for tasks that run in different instances
uid: Optional[str] = field(default=None)
def with_error(self, exc: Exception) -> "TaskResult":
"""Since errors might not always be pickle-able, set the traceback"""
self.messages.extend(format_tb(exc.__traceback__))
self.messages.append(str(exc))
return self
@dataclass
class TaskInfo: