diff --git a/export_manager.go b/export_manager.go index a445325..d3b15cc 100644 --- a/export_manager.go +++ b/export_manager.go @@ -5,6 +5,7 @@ import ( "fmt" "log/slog" "maps" + "strings" "sync" "time" ) @@ -116,9 +117,40 @@ func (em *ExportManager) exportBatch(ctx context.Context) { } } - if err := em.storage.(*SQLiteStorage).MarkAsExported(ctx, ids); err != nil { - slog.Error("Failed to mark entries as exported", "error", err) + backoff := time.Duration(0) + var lastErr error + + for attempt := 0; attempt <= em.config.RetryAttempts; attempt++ { + if attempt > 0 { + backoff = time.Duration(attempt) * em.config.RetryBackoff + time.Sleep(backoff) + } + err := em.storage.(*SQLiteStorage).MarkAsExported(ctx, ids) + if err == nil { + break + } + lastErr = err + if strings.Contains(err.Error(), "database is locked") { + continue + } else { + slog.Error("Failed to mark entries as exported", "error", err) + break + } } + + if lastErr != nil && backoff > 0 { + slog.Error("Failed to mark entries as exported after retries", "error", lastErr) + } + // if err := em.storage.(*SQLiteStorage).MarkAsExported(ctx, ids); err != nil { + // if strings.Contains(err.Error(), "database is locked") { + // time.Sleep(50 * time.Millisecond) + // err := em.storage.(*SQLiteStorage).MarkAsExported(ctx, ids) + // if err != nil { + // slog.Error("Failed to mark entries as exported", "error", err) + // } + // } + // slog.Error("Failed to mark entries as exported", "error", err) + // } } }