fix(PROJ-44): IMAP+POP3 Live-Import triggert OCR-Worker

Bisher haben nur der SMTP-Pfad und der Boot-Backfill ocrWorker.Submit
gerufen. IMAP- und POP3-Importer riefen nur idx.IndexSync auf —
neue Mails blieben dadurch dauerhaft in ocr_status='pending' (auf 132
44 Tage 54 Mails so haengen geblieben).

Fix: Importer-Strukturen bekommen einen optionalen ocrSubmit-Callback,
in main.go via SetOCRSubmit gehookt. Kein Import von internal/ocr in
die Importer-Packages -> kein Risiko von Cycles. Submit ist
non-blocking; bei Mails ohne Attachments markiert der Worker selbst
'skipped'.
This commit is contained in:
sysops
2026-05-10 22:23:24 +02:00
parent a44fd1ae44
commit 032892bc2b
3 changed files with 43 additions and 0 deletions
+13
View File
@@ -19,6 +19,8 @@ type Importer struct {
idx index.Indexer
logger *slog.Logger
TenantID *int64 // optional tenant assignment for stored mails
// PROJ-44: optional OCR enqueue hook, wired from main.go.
ocrSubmit func(mailID string, tenantID *int64)
}
// NewImporter creates a new Importer wired to the storage and index backends.
@@ -31,6 +33,12 @@ func NewImporter(store *Store, mailStore *storage.Store, idx index.Indexer, logg
}
}
// SetOCRSubmit installs a non-blocking callback that enqueues a mail for
// OCR processing. See imap.Importer.SetOCRSubmit for rationale (PROJ-44).
func (imp *Importer) SetOCRSubmit(fn func(mailID string, tenantID *int64)) {
imp.ocrSubmit = fn
}
// Run performs a full POP3 import for the given account. It is designed to be
// called as a goroutine: go imp.Run(context.Background(), accountID)
func (imp *Importer) Run(ctx context.Context, accountID int64) {
@@ -166,5 +174,10 @@ func (imp *Importer) storeAndIndex(raw []byte, log *slog.Logger) error {
// Non-fatal: mail is stored, just not searchable yet
}
// PROJ-44: enqueue OCR job for any mail with attachments.
if imp.ocrSubmit != nil && len(pm.Attachments) > 0 {
imp.ocrSubmit(id, imp.TenantID)
}
return nil
}