Fix snapshotter initialization and remove initial snapshot on startup

- Remove immediate snapshot when periodic goroutine starts
- Fix variable shadowing issue in snapshotter creation
- Add debug logging for snapshotter shutdown
- Snapshots now only occur after 10 minutes or on shutdown
This commit is contained in:
Jeffrey Paul 2025-07-28 00:06:39 +02:00
parent ae2ef2ae0c
commit 52cdcd5785
2 changed files with 6 additions and 7 deletions

View File

@ -73,12 +73,12 @@ func New(deps Dependencies) *RouteWatch {
// Create snapshotter unless disabled (for tests) // Create snapshotter unless disabled (for tests)
if os.Getenv("ROUTEWATCH_DISABLE_SNAPSHOTTER") != "1" { if os.Getenv("ROUTEWATCH_DISABLE_SNAPSHOTTER") != "1" {
snapshotter, err := snapshotter.New(deps.RoutingTable, deps.Logger) snap, err := snapshotter.New(deps.RoutingTable, deps.Logger)
if err != nil { if err != nil {
deps.Logger.Error("Failed to create snapshotter", "error", err) deps.Logger.Error("Failed to create snapshotter", "error", err)
// Continue without snapshotter // Continue without snapshotter
} else { } else {
rw.snapshotter = snapshotter rw.snapshotter = snap
} }
} }
@ -153,9 +153,12 @@ func (rw *RouteWatch) Run(ctx context.Context) error {
// Take final snapshot before shutdown if snapshotter is available // Take final snapshot before shutdown if snapshotter is available
if rw.snapshotter != nil { if rw.snapshotter != nil {
rw.logger.Info("Shutting down snapshotter")
if err := rw.snapshotter.Shutdown(); err != nil { if err := rw.snapshotter.Shutdown(); err != nil {
rw.logger.Error("Failed to shutdown snapshotter", "error", err) rw.logger.Error("Failed to shutdown snapshotter", "error", err)
} }
} else {
rw.logger.Info("No snapshotter available")
} }
return nil return nil

View File

@ -115,11 +115,7 @@ func (s *Snapshotter) periodicSnapshot() {
ticker := time.NewTicker(snapshotInterval) ticker := time.NewTicker(snapshotInterval)
defer ticker.Stop() defer ticker.Stop()
// Take an initial snapshot // Wait for the first interval before taking any snapshots
if err := s.TakeSnapshot(); err != nil {
s.logger.Error("Failed to take initial snapshot", "error", err)
}
for { for {
select { select {
case <-s.ctx.Done(): case <-s.ctx.Done():