feat(ocr): show translated progress messages during OCR processing
Backend sends progress codes (PREPARING, LOADING, ANALYZING, CREATING_BLOCKS:N, DONE:N, ERROR) via OcrJob.progressMessage. Frontend translates them via Paraglide (de/en/es) and displays below the spinner. - V27 migration: adds progress_message column to ocr_jobs - OcrAsyncRunner updates progress at each phase - Poll interval reduced to 2s for snappier updates Refs #226 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -47,6 +47,9 @@ public class OcrJob {
|
||||
@Builder.Default
|
||||
private int skippedCount = 0;
|
||||
|
||||
@Column(name = "progress_message")
|
||||
private String progressMessage;
|
||||
|
||||
@Column(name = "created_by")
|
||||
private UUID createdBy;
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public class OcrAsyncRunner {
|
||||
if (job == null) return;
|
||||
|
||||
job.setStatus(OcrJobStatus.RUNNING);
|
||||
ocrJobRepository.save(job);
|
||||
updateProgress(job, "PREPARING");
|
||||
|
||||
OcrJobDocument jobDoc = ocrJobDocumentRepository.findByJobIdAndDocumentId(jobId, documentId)
|
||||
.orElse(null);
|
||||
@@ -49,9 +49,19 @@ public class OcrAsyncRunner {
|
||||
Document doc = documentService.getDocumentById(documentId);
|
||||
|
||||
try {
|
||||
processDocument(documentId, doc, userId);
|
||||
updateProgress(job, "LOADING");
|
||||
clearExistingBlocks(documentId);
|
||||
String pdfUrl = fileService.generatePresignedUrl(doc.getFilePath());
|
||||
|
||||
updateProgress(job, "ANALYZING");
|
||||
List<OcrBlockResult> blocks = ocrClient.extractBlocks(pdfUrl, doc.getScriptType());
|
||||
|
||||
updateProgress(job, "CREATING_BLOCKS:" + blocks.size());
|
||||
createTranscriptionBlocks(documentId, blocks, userId, doc.getFileHash());
|
||||
|
||||
job.setStatus(OcrJobStatus.DONE);
|
||||
job.setProcessedDocuments(1);
|
||||
updateProgress(job, "DONE:" + blocks.size());
|
||||
if (jobDoc != null) {
|
||||
jobDoc.setStatus(OcrDocumentStatus.DONE);
|
||||
ocrJobDocumentRepository.save(jobDoc);
|
||||
@@ -60,13 +70,17 @@ public class OcrAsyncRunner {
|
||||
log.error("OCR processing failed for document {}", documentId, e);
|
||||
job.setStatus(OcrJobStatus.FAILED);
|
||||
job.setErrorCount(1);
|
||||
updateProgress(job, "ERROR");
|
||||
if (jobDoc != null) {
|
||||
jobDoc.setStatus(OcrDocumentStatus.FAILED);
|
||||
jobDoc.setErrorMessage(e.getMessage());
|
||||
ocrJobDocumentRepository.save(jobDoc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateProgress(OcrJob job, String message) {
|
||||
job.setProgressMessage(message);
|
||||
ocrJobRepository.save(job);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE ocr_jobs ADD COLUMN progress_message TEXT;
|
||||
Reference in New Issue
Block a user