feat: optimize retry logic for marking logs as exported
This commit is contained in:
parent
368a3cf062
commit
49095b78d4
1 changed files with 34 additions and 2 deletions
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"maps"
|
"maps"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
@ -116,9 +117,40 @@ func (em *ExportManager) exportBatch(ctx context.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := em.storage.(*SQLiteStorage).MarkAsExported(ctx, ids); err != nil {
|
backoff := time.Duration(0)
|
||||||
slog.Error("Failed to mark entries as exported", "error", err)
|
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)
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue