A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Enhancement: show small task summary in system status (#12634)
shamoon5bb9241e9a4a
diff --git a/src-ui/src/app/components/common/system-status-dialog/system-status-dialog.component.html b/src-ui/src/app/components/common/system-status-dialog/system-status-dialog.component.htmlindex d57485214..d9194fd2c 100644--- a/src-ui/src/app/components/common/system-status-dialog/system-status-dialog.component.html+++ b/src-ui/src/app/components/common/system-status-dialog/system-status-dialog.component.html@@ -142,6 +142,31 @@}</ng-template></dd>+ <dt i18n>Recent Task Activity <span class="small text-muted fw-light">({{status.tasks.summary.days}} days)</span></dt>+ <dd class="mb-0">+ @if (status.tasks.summary.total_count > 0) {+ <ul class="list-group border-light mt-2">+ <li class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">+ <span class="small"><ng-container i18n>Total</ng-container>:</span>+ <span class="badge bg-light rounded-pill">{{status.tasks.summary.total_count}}</span>+ </li>+ <li class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">+ <span class="small"><ng-container i18n>Successful</ng-container>:</span>+ <span class="badge bg-primary rounded-pill">{{status.tasks.summary.success_count}}</span>+ </li>+ <li class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">+ <span class="small"><ng-container i18n>Failed</ng-container>:</span>+ <span class="badge bg-danger rounded-pill">{{status.tasks.summary.failure_count}}</span>+ </li>+ <li class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">+ <span class="small"><ng-container i18n>Pending</ng-container>:</span>+ <span class="badge bg-warning rounded-pill">{{status.tasks.summary.pending_count}}</span>+ </li>+ </ul>+ } @else {+ <span class="small text-muted" i18n>No recent tasks</span>+ }+ </dd></dl></div></div>diff --git a/src-ui/src/app/components/common/system-status-dialog/system-status-dialog.component.spec.ts b/src-ui/src/app/components/common/system-status-dialog/system-status-dialog.component.spec.tsindex 29bad431e..4c69feed4 100644--- a/src-ui/src/app/components/common/system-status-dialog/system-status-dialog.component.spec.ts+++ b/src-ui/src/app/components/common/system-status-dialog/system-status-dialog.component.spec.ts@@ -71,6 +71,13 @@ const status: SystemStatus = {llmindex_status: SystemStatusItemStatus.OK,llmindex_last_modified: new Date().toISOString(),llmindex_error: null,+ summary: {+ days: 30,+ total_count: 12,+ pending_count: 1,+ success_count: 10,+ failure_count: 1,+ },},}diff --git a/src-ui/src/app/data/system-status.ts b/src-ui/src/app/data/system-status.tsindex 7dcbffa20..41cc738cc 100644--- a/src-ui/src/app/data/system-status.ts+++ b/src-ui/src/app/data/system-status.ts@@ -47,6 +47,13 @@ export interface SystemStatus {llmindex_status: SystemStatusItemStatusllmindex_last_modified: string // ISO date stringllmindex_error: string+ summary: {+ days: number+ total_count: number+ pending_count: number+ success_count: number+ failure_count: number+ }}websocket_connected?: SystemStatusItemStatus // added client-side}diff --git a/src/documents/tests/test_api_status.py b/src/documents/tests/test_api_status.pyindex bb0039e67..72f1e269b 100644--- a/src/documents/tests/test_api_status.py+++ b/src/documents/tests/test_api_status.py@@ -1,12 +1,14 @@import osimport shutilimport tempfile+from datetime import timedeltafrom pathlib import Pathfrom unittest import mockfrom django.contrib.auth.models import Permissionfrom django.contrib.auth.models import Userfrom django.test import override_settings+from django.utils import timezonefrom rest_framework import statusfrom rest_framework.test import APITestCase@@ -76,6 +78,11 @@ class TestSystemStatus(APITestCase):self.assertEqual(response.data["tasks"]["redis_url"], "redis://localhost:6379")self.assertEqual(response.data["tasks"]["redis_status"], "ERROR")self.assertIsNotNone(response.data["tasks"]["redis_error"])+ self.assertEqual(response.data["tasks"]["summary"]["days"], 30)+ self.assertEqual(response.data["tasks"]["summary"]["total_count"], 0)+ self.assertEqual(response.data["tasks"]["summary"]["success_count"], 0)+ self.assertEqual(response.data["tasks"]["summary"]["failure_count"], 0)+ self.assertEqual(response.data["tasks"]["summary"]["pending_count"], 0)def test_system_status_insufficient_permissions(self) -> None:"""@@ -436,3 +443,32 @@ class TestSystemStatus(APITestCase):self.assertEqual(response.status_code, status.HTTP_200_OK)self.assertEqual(response.data["tasks"]["llmindex_status"], "ERROR")self.assertIsNotNone(response.data["tasks"]["llmindex_error"])++ def test_system_status_includes_recent_task_summary(self) -> None:+ PaperlessTaskFactory(+ task_type=PaperlessTask.TaskType.CONSUME_FILE,+ status=PaperlessTask.Status.SUCCESS,+ )+ PaperlessTaskFactory(+ task_type=PaperlessTask.TaskType.CONSUME_FILE,+ status=PaperlessTask.Status.FAILURE,+ )+ PaperlessTaskFactory(+ task_type=PaperlessTask.TaskType.SANITY_CHECK,+ status=PaperlessTask.Status.PENDING,+ )+ PaperlessTaskFactory(+ task_type=PaperlessTask.TaskType.MAIL_FETCH,+ status=PaperlessTask.Status.SUCCESS,+ date_created=timezone.now() - timedelta(days=45),+ )++ self.client.force_login(self.user)+ response = self.client.get(self.ENDPOINT)++ self.assertEqual(response.status_code, status.HTTP_200_OK)+ self.assertEqual(response.data["tasks"]["summary"]["days"], 30)+ self.assertEqual(response.data["tasks"]["summary"]["total_count"], 3)+ self.assertEqual(response.data["tasks"]["summary"]["success_count"], 1)+ self.assertEqual(response.data["tasks"]["summary"]["failure_count"], 1)+ self.assertEqual(response.data["tasks"]["summary"]["pending_count"], 1)diff --git a/src/documents/views.py b/src/documents/views.pyindex 217550634..74c7733cf 100644--- a/src/documents/views.py+++ b/src/documents/views.py@@ -4597,6 +4597,16 @@ class CustomFieldViewSet(PermissionsAwareDocumentCountMixin, ModelViewSet[Custom"redis_status": serializers.CharField(),"redis_error": serializers.CharField(),"celery_status": serializers.CharField(),+ "summary": inline_serializer(+ name="TasksSummaryOverview",+ fields={+ "days": serializers.IntegerField(),+ "total_count": serializers.IntegerField(),+ "pending_count": serializers.IntegerField(),+ "success_count": serializers.IntegerField(),+ "failure_count": serializers.IntegerField(),+ },+ ),},),"index": inline_serializer(@@ -4630,6 +4640,7 @@ class CustomFieldViewSet(PermissionsAwareDocumentCountMixin, ModelViewSet[Custom)class SystemStatusView(PassUserMixin):permission_classes = (IsAuthenticated,)+ TASK_SUMMARY_DAYS = 30def get(self, request, format=None):if not has_system_status_permission(request.user):@@ -4796,6 +4807,29 @@ class SystemStatusView(PassUserMixin):last_llmindex_update.date_done if last_llmindex_update else None)+ summary_cutoff = timezone.now() - timedelta(days=self.TASK_SUMMARY_DAYS)+ task_summary_agg = PaperlessTask.objects.filter(+ date_created__gte=summary_cutoff,+ ).aggregate(+ total_count=Count("id"),+ pending_count=Count(+ "id",+ filter=Q(status=PaperlessTask.Status.PENDING),+ ),+ success_count=Count(+ "id",+ filter=Q(status=PaperlessTask.Status.SUCCESS),+ ),+ failure_count=Count(+ "id",+ filter=Q(status=PaperlessTask.Status.FAILURE),+ ),+ )+ task_summary = {+ "days": self.TASK_SUMMARY_DAYS,+ **task_summary_agg,+ }+return Response({"pngx_version": current_version,@@ -4836,6 +4870,7 @@ class SystemStatusView(PassUserMixin):"llmindex_status": llmindex_status,"llmindex_last_modified": llmindex_last_modified,"llmindex_error": llmindex_error,+ "summary": task_summary,},},)