Use last successful task for classifier last trained

This commit is contained in:
shamoon 2024-02-15 00:07:52 -08:00
parent dfee524fdf
commit fc2c3dfc1a
6 changed files with 26 additions and 13 deletions

View File

@ -4519,10 +4519,6 @@
<context context-type="sourcefile">src/app/components/common/system-status-dialog/system-status-dialog.component.html</context> <context context-type="sourcefile">src/app/components/common/system-status-dialog/system-status-dialog.component.html</context>
<context context-type="linenumber">119</context> <context context-type="linenumber">119</context>
</context-group> </context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/system-status-dialog/system-status-dialog.component.html</context>
<context context-type="linenumber">135</context>
</context-group>
</trans-unit> </trans-unit>
<trans-unit id="46628344485199198" datatype="html"> <trans-unit id="46628344485199198" datatype="html">
<source>Classifier</source> <source>Classifier</source>
@ -4531,6 +4527,13 @@
<context context-type="linenumber">121</context> <context context-type="linenumber">121</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="6096684179126491743" datatype="html">
<source>Last Trained</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/system-status-dialog/system-status-dialog.component.html</context>
<context context-type="linenumber">135</context>
</context-group>
</trans-unit>
<trans-unit id="6732151329960766506" datatype="html"> <trans-unit id="6732151329960766506" datatype="html">
<source>Copy Raw Error</source> <source>Copy Raw Error</source>
<context-group purpose="location"> <context-group purpose="location">

View File

@ -413,7 +413,7 @@ describe('SettingsComponent', () => {
index_last_modified: new Date().toISOString(), index_last_modified: new Date().toISOString(),
index_error: null, index_error: null,
classifier_status: SystemStatusItemStatus.OK, classifier_status: SystemStatusItemStatus.OK,
classifier_last_modified: new Date().toISOString(), classifier_last_trained: new Date().toISOString(),
classifier_error: null, classifier_error: null,
}, },
} }

View File

@ -122,7 +122,7 @@
<dd> <dd>
{{status.tasks.classifier_status}} {{status.tasks.classifier_status}}
@if (status.tasks.classifier_status === 'OK') { @if (status.tasks.classifier_status === 'OK') {
@if (isStale(status.tasks.classifier_last_modified)) { @if (isStale(status.tasks.classifier_last_trained)) {
<i-bs name="exclamation-triangle-fill" class="text-warning ms-1" [ngbPopover]="classifierStatus" triggers="mouseenter:mouseleave"></i-bs> <i-bs name="exclamation-triangle-fill" class="text-warning ms-1" [ngbPopover]="classifierStatus" triggers="mouseenter:mouseleave"></i-bs>
} @else { } @else {
<i-bs name="check-circle-fill" class="text-primary ms-1" [ngbPopover]="classifierStatus" triggers="mouseenter:mouseleave"></i-bs> <i-bs name="check-circle-fill" class="text-primary ms-1" [ngbPopover]="classifierStatus" triggers="mouseenter:mouseleave"></i-bs>
@ -132,7 +132,7 @@
} }
</dd> </dd>
<ng-template #classifierStatus> <ng-template #classifierStatus>
<h6><ng-container i18n>Last Updated</ng-container>:</h6> <span class="font-monospace small">{{status.tasks.classifier_last_modified | customDate:'medium'}}</span> <h6><ng-container i18n>Last Trained</ng-container>:</h6> <span class="font-monospace small">{{status.tasks.classifier_last_trained | customDate:'medium'}}</span>
</ng-template> </ng-template>
</dl> </dl>
</div> </div>

View File

@ -45,7 +45,7 @@ const status: SystemStatus = {
index_last_modified: new Date().toISOString(), index_last_modified: new Date().toISOString(),
index_error: null, index_error: null,
classifier_status: SystemStatusItemStatus.OK, classifier_status: SystemStatusItemStatus.OK,
classifier_last_modified: new Date().toISOString(), classifier_last_trained: new Date().toISOString(),
classifier_error: null, classifier_error: null,
}, },
} }

View File

@ -35,7 +35,7 @@ export interface SystemStatus {
index_last_modified: string // ISO date string index_last_modified: string // ISO date string
index_error: string index_error: string
classifier_status: SystemStatusItemStatus classifier_status: SystemStatusItemStatus
classifier_last_modified: string // ISO date string classifier_last_trained: string // ISO date string
classifier_error: string classifier_error: string
} }
} }

View File

@ -14,6 +14,7 @@ from unicodedata import normalize
from urllib.parse import quote from urllib.parse import quote
import pathvalidate import pathvalidate
from django.apps import apps
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db import connections from django.db import connections
@ -1621,12 +1622,21 @@ class SystemStatusView(GenericAPIView, PassUserMixin):
try: try:
load_classifier() load_classifier()
classifier_status = "OK" classifier_status = "OK"
classifier_last_modified = make_aware( task_result_model = apps.get_model("django_celery_results", "taskresult")
datetime.fromtimestamp(os.path.getmtime(settings.MODEL_FILE)), 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: except Exception as e:
classifier_status = "ERROR" classifier_status = "ERROR"
classifier_last_modified = None classifier_last_trained = None
classifier_error = "Error loading classifier, check logs for more detail." classifier_error = "Error loading classifier, check logs for more detail."
logger.exception(f"System status error loading classifier: {e}") logger.exception(f"System status error loading classifier: {e}")
@ -1660,7 +1670,7 @@ class SystemStatusView(GenericAPIView, PassUserMixin):
"index_last_modified": index_last_modified, "index_last_modified": index_last_modified,
"index_error": index_error, "index_error": index_error,
"classifier_status": classifier_status, "classifier_status": classifier_status,
"classifier_last_modified": classifier_last_modified, "classifier_last_trained": classifier_last_trained,
"classifier_error": classifier_error, "classifier_error": classifier_error,
}, },
}, },