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:
@@ -23,6 +23,9 @@ type Importer struct {
|
||||
mailStore *storage.Store
|
||||
idx index.Indexer
|
||||
logger *slog.Logger
|
||||
// PROJ-44: optional hook into the async OCR worker. Wired in main.go
|
||||
// via SetOCRSubmit so the imap package does not import internal/ocr.
|
||||
ocrSubmit func(mailID string, tenantID *int64)
|
||||
}
|
||||
|
||||
// NewImporter creates a new Importer wired to the storage and index backends.
|
||||
@@ -35,6 +38,13 @@ func NewImporter(store *Store, mailStore *storage.Store, idx index.Indexer, logg
|
||||
}
|
||||
}
|
||||
|
||||
// SetOCRSubmit installs a non-blocking callback that enqueues a mail for
|
||||
// OCR processing. If never called, IMAP-imported mails are not OCR'd —
|
||||
// they remain in ocr_status='pending' forever (PROJ-44 fix).
|
||||
func (imp *Importer) SetOCRSubmit(fn func(mailID string, tenantID *int64)) {
|
||||
imp.ocrSubmit = fn
|
||||
}
|
||||
|
||||
// Run performs a full IMAP 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) {
|
||||
@@ -271,5 +281,12 @@ func (imp *Importer) storeAndIndex(raw []byte, tenantID *int64, log *slog.Logger
|
||||
// Non-fatal: mail is stored, just not searchable yet
|
||||
}
|
||||
|
||||
// PROJ-44: enqueue OCR job for any mail with attachments. Submit is
|
||||
// non-blocking; mails with no OCR-eligible parts get marked 'skipped'
|
||||
// by the worker, so the queue stays in sync regardless.
|
||||
if imp.ocrSubmit != nil && len(pm.Attachments) > 0 {
|
||||
imp.ocrSubmit(id, tenantID)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user