Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some logging when looking up Task objects #1399

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion controlpanel/api/tasks/handlers/base.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand Down
Loading