From fc2c3dfc1ab4ab630682d3e6fc056d83bc29c600 Mon Sep 17 00:00:00 2001
From: shamoon <4887959+shamoon@users.noreply.github.com>
Date: Thu, 15 Feb 2024 00:07:52 -0800
Subject: [PATCH] Use last successful task for classifier last trained
---
src-ui/messages.xlf | 11 +++++++----
.../admin/settings/settings.component.spec.ts | 2 +-
.../system-status-dialog.component.html | 4 ++--
.../system-status-dialog.component.spec.ts | 2 +-
src-ui/src/app/data/system-status.ts | 2 +-
src/documents/views.py | 18 ++++++++++++++----
6 files changed, 26 insertions(+), 13 deletions(-)
diff --git a/src-ui/messages.xlf b/src-ui/messages.xlf
index ec5ce8a79..a111abc56 100644
--- a/src-ui/messages.xlf
+++ b/src-ui/messages.xlf
@@ -4519,10 +4519,6 @@
src/app/components/common/system-status-dialog/system-status-dialog.component.html
119
-
- src/app/components/common/system-status-dialog/system-status-dialog.component.html
- 135
-
Classifier
@@ -4531,6 +4527,13 @@
121
+
+ Last Trained
+
+ src/app/components/common/system-status-dialog/system-status-dialog.component.html
+ 135
+
+
Copy Raw Error
diff --git a/src-ui/src/app/components/admin/settings/settings.component.spec.ts b/src-ui/src/app/components/admin/settings/settings.component.spec.ts
index 56c065bd8..6110f7d1d 100644
--- a/src-ui/src/app/components/admin/settings/settings.component.spec.ts
+++ b/src-ui/src/app/components/admin/settings/settings.component.spec.ts
@@ -413,7 +413,7 @@ describe('SettingsComponent', () => {
index_last_modified: new Date().toISOString(),
index_error: null,
classifier_status: SystemStatusItemStatus.OK,
- classifier_last_modified: new Date().toISOString(),
+ classifier_last_trained: new Date().toISOString(),
classifier_error: null,
},
}
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.html
index 83754cef4..d74e28d8d 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
@@ -122,7 +122,7 @@
{{status.tasks.classifier_status}}
@if (status.tasks.classifier_status === 'OK') {
- @if (isStale(status.tasks.classifier_last_modified)) {
+ @if (isStale(status.tasks.classifier_last_trained)) {
} @else {
@@ -132,7 +132,7 @@
}
- Last Updated:
{{status.tasks.classifier_last_modified | customDate:'medium'}}
+ Last Trained:
{{status.tasks.classifier_last_trained | customDate:'medium'}}
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.ts
index 8aa159edf..13baa363a 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
@@ -45,7 +45,7 @@ const status: SystemStatus = {
index_last_modified: new Date().toISOString(),
index_error: null,
classifier_status: SystemStatusItemStatus.OK,
- classifier_last_modified: new Date().toISOString(),
+ classifier_last_trained: new Date().toISOString(),
classifier_error: null,
},
}
diff --git a/src-ui/src/app/data/system-status.ts b/src-ui/src/app/data/system-status.ts
index fac697961..247535602 100644
--- a/src-ui/src/app/data/system-status.ts
+++ b/src-ui/src/app/data/system-status.ts
@@ -35,7 +35,7 @@ export interface SystemStatus {
index_last_modified: string // ISO date string
index_error: string
classifier_status: SystemStatusItemStatus
- classifier_last_modified: string // ISO date string
+ classifier_last_trained: string // ISO date string
classifier_error: string
}
}
diff --git a/src/documents/views.py b/src/documents/views.py
index 18d022b34..4003c33df 100644
--- a/src/documents/views.py
+++ b/src/documents/views.py
@@ -14,6 +14,7 @@ from unicodedata import normalize
from urllib.parse import quote
import pathvalidate
+from django.apps import apps
from django.conf import settings
from django.contrib.auth.models import User
from django.db import connections
@@ -1621,12 +1622,21 @@ class SystemStatusView(GenericAPIView, PassUserMixin):
try:
load_classifier()
classifier_status = "OK"
- classifier_last_modified = make_aware(
- datetime.fromtimestamp(os.path.getmtime(settings.MODEL_FILE)),
+ task_result_model = apps.get_model("django_celery_results", "taskresult")
+ result = (
+ task_result_model.objects.filter(
+ task_name="documents.tasks.train_classifier",
+ status="SUCCESS",
+ )
+ .order_by(
+ "-date_done",
+ )
+ .first()
)
+ classifier_last_trained = result.date_done if result else None
except Exception as e:
classifier_status = "ERROR"
- classifier_last_modified = None
+ classifier_last_trained = None
classifier_error = "Error loading classifier, check logs for more detail."
logger.exception(f"System status error loading classifier: {e}")
@@ -1660,7 +1670,7 @@ class SystemStatusView(GenericAPIView, PassUserMixin):
"index_last_modified": index_last_modified,
"index_error": index_error,
"classifier_status": classifier_status,
- "classifier_last_modified": classifier_last_modified,
+ "classifier_last_trained": classifier_last_trained,
"classifier_error": classifier_error,
},
},