From a6a1c96d4469d47901e8d4009b7a8b69fc9c2edc Mon Sep 17 00:00:00 2001 From: Marc 'risson' Schmitt Date: Thu, 28 Dec 2023 12:41:51 +0100 Subject: [PATCH] fix startup Signed-off-by: Marc 'risson' Schmitt --- authentik/events/monitored_tasks.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/authentik/events/monitored_tasks.py b/authentik/events/monitored_tasks.py index efb598be3..4dbd0678c 100644 --- a/authentik/events/monitored_tasks.py +++ b/authentik/events/monitored_tasks.py @@ -6,6 +6,7 @@ from timeit import default_timer from typing import Any, Optional from django.core.cache import cache +from django.db.utils import ProgrammingError from django.utils.translation import gettext_lazy as _ from structlog.stdlib import get_logger from tenant_schemas_celery.task import TenantTask @@ -101,8 +102,13 @@ class TaskInfo: duration = max(self.finish_timestamp - start, 0) except TypeError: duration = 0 + try: + tenant = get_current_tenant().tenant_uuid + # DB not yet initialized, let's not fail + except ProgrammingError: + tenant = "" GAUGE_TASKS.labels( - tenant=get_current_tenant().tenant_uuid, + tenant=tenant, task_name=self.task_name.split(":")[0], task_uid=self.result.uid or "", status=self.result.status.name.lower(),