enterprise: fix system task missing set_status (#8455)
* fix missing set_status on enterprise task Signed-off-by: Jens Langhammer <jens@goauthentik.io> * default task status to successful Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
"""Enterprise tasks"""
|
"""Enterprise tasks"""
|
||||||
|
|
||||||
from authentik.enterprise.models import LicenseKey
|
from authentik.enterprise.models import LicenseKey
|
||||||
|
from authentik.events.models import TaskStatus
|
||||||
from authentik.events.system_tasks import SystemTask, prefill_task
|
from authentik.events.system_tasks import SystemTask, prefill_task
|
||||||
from authentik.root.celery import CELERY_APP
|
from authentik.root.celery import CELERY_APP
|
||||||
|
|
||||||
@ -10,3 +11,4 @@ from authentik.root.celery import CELERY_APP
|
|||||||
def enterprise_update_usage(self: SystemTask):
|
def enterprise_update_usage(self: SystemTask):
|
||||||
"""Update enterprise license status"""
|
"""Update enterprise license status"""
|
||||||
LicenseKey.get_total().record_usage()
|
LicenseKey.get_total().record_usage()
|
||||||
|
self.set_status(TaskStatus.SUCCESSFUL)
|
||||||
|
|||||||
@ -18,7 +18,7 @@ GAUGE_TASKS = Gauge(
|
|||||||
SYSTEM_TASK_TIME = Histogram(
|
SYSTEM_TASK_TIME = Histogram(
|
||||||
"authentik_system_tasks_time_seconds",
|
"authentik_system_tasks_time_seconds",
|
||||||
"Runtime of system tasks",
|
"Runtime of system tasks",
|
||||||
["tenant"],
|
["tenant", "task_name", "task_uid"],
|
||||||
)
|
)
|
||||||
SYSTEM_TASK_STATUS = Gauge(
|
SYSTEM_TASK_STATUS = Gauge(
|
||||||
"authentik_system_tasks_status",
|
"authentik_system_tasks_status",
|
||||||
|
|||||||
@ -651,6 +651,8 @@ class SystemTask(SerializerModel, ExpiringModel):
|
|||||||
).set(self.duration)
|
).set(self.duration)
|
||||||
SYSTEM_TASK_TIME.labels(
|
SYSTEM_TASK_TIME.labels(
|
||||||
tenant=connection.schema_name,
|
tenant=connection.schema_name,
|
||||||
|
task_name=self.name,
|
||||||
|
task_uid=self.uid or "",
|
||||||
).observe(self.duration)
|
).observe(self.duration)
|
||||||
SYSTEM_TASK_STATUS.labels(
|
SYSTEM_TASK_STATUS.labels(
|
||||||
tenant=connection.schema_name,
|
tenant=connection.schema_name,
|
||||||
|
|||||||
@ -24,7 +24,7 @@ class SystemTask(TenantTask):
|
|||||||
# For tasks that should only be listed if they failed, set this to False
|
# For tasks that should only be listed if they failed, set this to False
|
||||||
save_on_success: bool
|
save_on_success: bool
|
||||||
|
|
||||||
_status: Optional[TaskStatus]
|
_status: TaskStatus
|
||||||
_messages: list[str]
|
_messages: list[str]
|
||||||
|
|
||||||
_uid: Optional[str]
|
_uid: Optional[str]
|
||||||
@ -34,6 +34,7 @@ class SystemTask(TenantTask):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs) -> None:
|
def __init__(self, *args, **kwargs) -> None:
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
self._status = TaskStatus.SUCCESSFUL
|
||||||
self.save_on_success = True
|
self.save_on_success = True
|
||||||
self._uid = None
|
self._uid = None
|
||||||
self._status = None
|
self._status = None
|
||||||
|
|||||||
Reference in New Issue
Block a user