feat: implement log-rotation for local sqlite storage

This commit is contained in:
Patryk Hegenberg 2025-09-25 10:23:48 +02:00
parent 4d3782902a
commit 1f07632ae2
5 changed files with 322 additions and 28 deletions

12
main.go
View file

@ -31,14 +31,22 @@ func main() {
var storage StorageInterface
if cfg.LocalStorage.Enable {
sqliteStorage, err := NewSQLiteStorage(cfg.LocalStorage.DBPath)
rotationConfig := StorageRotationConfig{
MaxSizeBytes: cfg.LocalStorage.RotationConfig.MaxSizeBytes,
MaxAgeHours: cfg.LocalStorage.RotationConfig.GetMaxAge(),
MaxFiles: cfg.LocalStorage.RotationConfig.MaxFiles,
CheckIntervalMinutes: cfg.LocalStorage.RotationConfig.GetCheckInterval(),
ArchiveDir: cfg.LocalStorage.RotationConfig.ArchiveDir,
}
sqliteStorage, err := NewSQLiteStorageWithRotation(cfg.LocalStorage.DBPath, rotationConfig)
if err != nil {
slog.Error("failed to initialize SQLite storage", "error", err)
os.Exit(1)
}
storage = sqliteStorage
defer storage.Close()
slog.Info("SQLite storage initialized", "path", cfg.LocalStorage.DBPath)
slog.Info("SQLite storage with rotation initialized", "path", cfg.LocalStorage.DBPath)
} else {
slog.Error("Local storage is disabled, but it's required for the new architecture")
os.Exit(1)