diff --git a/controlpanel/api/tasks/handlers/base.py b/controlpanel/api/tasks/handlers/base.py index 5dd70f98..129b8488 100644 --- a/controlpanel/api/tasks/handlers/base.py +++ b/controlpanel/api/tasks/handlers/base.py @@ -1,9 +1,12 @@ # Third-party +import structlog from celery import Task as CeleryTask # First-party/Local from controlpanel.api.models import Task +log = structlog.getLogger(__name__) + class BaseTaskHandler(CeleryTask): # can be applied to project settings also @@ -21,7 +24,12 @@ def complete(self): self.task_obj.save() def get_task_obj(self): - return Task.objects.filter(task_id=self.request.id).first() + task_id = self.request.id + log.info(f"Getting task object with ID: {task_id}") + task = Task.objects.filter(task_id=task_id).first() + if not task: + log.warn(f"Task object not found with ID: {task_id}. Continuing...") + return task def run(self, *args, **kwargs): self.task_obj = self.get_task_obj()