feat(PROJ-44): ocr_chars-Spalte + SetOCRResult-Helper
DB-Schema bekommt eine idempotente ocr_chars BIGINT-Spalte (Default 0). SetOCRResult schreibt status und chars atomar; GetOCRMeta liest beide mit COALESCE-Defaults. Der OCR-Worker ersetzt jeden SetOCRStatus-Call durch SetOCRResult und uebergibt die extrahierte Zeichenzahl bei 'done'.
This commit is contained in:
+10
-9
@@ -137,26 +137,26 @@ func (w *Worker) process(ctx context.Context, job Job) {
|
||||
logger := w.logger.With("mail_id", job.MailID, "tenant_id", job.TenantID)
|
||||
|
||||
if w.store.OCREnabled(ctx, job.TenantID) == false {
|
||||
_ = w.store.SetOCRStatus(ctx, job.MailID, "disabled")
|
||||
_ = w.store.SetOCRResult(ctx, job.MailID, "disabled", 0)
|
||||
return
|
||||
}
|
||||
|
||||
raw, err := w.store.Load(job.MailID)
|
||||
if err != nil {
|
||||
logger.Warn("ocr worker: load failed", "err", err)
|
||||
_ = w.store.SetOCRStatus(ctx, job.MailID, "failed")
|
||||
_ = w.store.SetOCRResult(ctx, job.MailID, "failed", 0)
|
||||
return
|
||||
}
|
||||
|
||||
pm, err := mailparser.Parse(raw)
|
||||
if err != nil {
|
||||
logger.Warn("ocr worker: parse failed", "err", err)
|
||||
_ = w.store.SetOCRStatus(ctx, job.MailID, "failed")
|
||||
_ = w.store.SetOCRResult(ctx, job.MailID, "failed", 0)
|
||||
return
|
||||
}
|
||||
|
||||
if len(pm.Attachments) == 0 {
|
||||
_ = w.store.SetOCRStatus(ctx, job.MailID, "skipped")
|
||||
_ = w.store.SetOCRResult(ctx, job.MailID, "skipped", 0)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ func (w *Worker) process(ctx context.Context, job Job) {
|
||||
}
|
||||
|
||||
if processed == 0 {
|
||||
_ = w.store.SetOCRStatus(ctx, job.MailID, "skipped")
|
||||
_ = w.store.SetOCRResult(ctx, job.MailID, "skipped", 0)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -191,15 +191,16 @@ func (w *Worker) process(ctx context.Context, job Job) {
|
||||
updater, ok := idx.(index.AttachmentTextUpdater)
|
||||
if !ok {
|
||||
logger.Warn("ocr worker: indexer does not support AttachmentTextUpdater — text dropped")
|
||||
_ = w.store.SetOCRStatus(ctx, job.MailID, "failed")
|
||||
_ = w.store.SetOCRResult(ctx, job.MailID, "failed", 0)
|
||||
return
|
||||
}
|
||||
if err := updater.UpdateAttachmentText(job.MailID, combined.String()); err != nil {
|
||||
logger.Warn("ocr worker: index update failed", "err", err)
|
||||
_ = w.store.SetOCRStatus(ctx, job.MailID, "failed")
|
||||
_ = w.store.SetOCRResult(ctx, job.MailID, "failed", 0)
|
||||
return
|
||||
}
|
||||
|
||||
_ = w.store.SetOCRStatus(ctx, job.MailID, "done")
|
||||
logger.Info("ocr worker: indexed", "attachments", processed, "chars", combined.Len())
|
||||
chars := int64(combined.Len())
|
||||
_ = w.store.SetOCRResult(ctx, job.MailID, "done", chars)
|
||||
logger.Info("ocr worker: indexed", "attachments", processed, "chars", chars)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user