From 95e31769e8ad0af57370a172391d3ca2dda6a9e1 Mon Sep 17 00:00:00 2001 From: Michael Collins <15347726+michaeljcollinsuk@users.noreply.github.com> Date: Fri, 29 Nov 2024 12:49:00 +0000 Subject: [PATCH] Add some logging when looking up Task objects --- controlpanel/api/tasks/handlers/base.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/controlpanel/api/tasks/handlers/base.py b/controlpanel/api/tasks/handlers/base.py index 5dd70f982..129b8488d 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()