diff --git a/authentik/admin/api/tasks.py b/authentik/admin/api/tasks.py index c9ae28951..8ded6de49 100644 --- a/authentik/admin/api/tasks.py +++ b/authentik/admin/api/tasks.py @@ -7,7 +7,13 @@ from django.utils.translation import gettext_lazy as _ from drf_spectacular.types import OpenApiTypes from drf_spectacular.utils import OpenApiParameter, OpenApiResponse, extend_schema from rest_framework.decorators import action -from rest_framework.fields import CharField, ChoiceField, DateTimeField, ListField +from rest_framework.fields import ( + CharField, + ChoiceField, + DateTimeField, + ListField, + SerializerMethodField, +) from rest_framework.permissions import IsAdminUser from rest_framework.request import Request from rest_framework.response import Response @@ -26,6 +32,7 @@ class TaskSerializer(PassiveSerializer): task_name = CharField() task_description = CharField() task_finish_timestamp = DateTimeField(source="finish_time") + task_duration = SerializerMethodField() status = ChoiceField( source="result.status.name", @@ -33,7 +40,11 @@ class TaskSerializer(PassiveSerializer): ) messages = ListField(source="result.messages") - def to_representation(self, instance): + def get_task_duration(self, instance: TaskInfo) -> int: + """Get the duration a task took to run""" + return max(instance.finish_timestamp - instance.start_timestamp, 0) + + def to_representation(self, instance: TaskInfo): """When a new version of authentik adds fields to TaskInfo, the API will fail with an AttributeError, as the classes are pickled in cache. In that case, just delete the info""" diff --git a/schema.yml b/schema.yml index 8aba83abe..1cd8d2eb7 100644 --- a/schema.yml +++ b/schema.yml @@ -37157,6 +37157,9 @@ components: task_finish_timestamp: type: string format: date-time + task_duration: + type: integer + readOnly: true status: $ref: '#/components/schemas/TaskStatusEnum' messages: @@ -37166,6 +37169,7 @@ components: - messages - status - task_description + - task_duration - task_finish_timestamp - task_name TaskStatusEnum: diff --git a/web/src/admin/system-tasks/SystemTaskListPage.ts b/web/src/admin/system-tasks/SystemTaskListPage.ts index 3fafd1708..c2f18809a 100644 --- a/web/src/admin/system-tasks/SystemTaskListPage.ts +++ b/web/src/admin/system-tasks/SystemTaskListPage.ts @@ -82,6 +82,16 @@ export class SystemTaskListPage extends TablePage { return html`
+
+
+ ${t`Duration`} +
+
+
+ ${t`${Math.round(item.taskDuration)} seconds`} +
+
+
${t`Messages`}