Skip to content

Commit

Permalink
Don't call ticker.Reset (#1162)
Browse files Browse the repository at this point in the history
Tickers are periodic: https://pkg.go.dev/time#NewTicker

> The ticker will adjust the time interval or drop ticks to make up for slow receivers
  • Loading branch information
serprex authored Jan 26, 2024
1 parent 58b6010 commit 9d4065b
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 12 deletions.
4 changes: 1 addition & 3 deletions flow/activities/flowable.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,8 +721,7 @@ func (a *FlowableActivity) SendWALHeartbeat(ctx context.Context) error {
return nil
}

sendTimeout := 10 * time.Minute
ticker := time.NewTicker(sendTimeout)
ticker := time.NewTicker(10 * time.Minute)
defer ticker.Stop()

activity.RecordHeartbeat(ctx, "sending walheartbeat every 10 minutes")
Expand Down Expand Up @@ -768,7 +767,6 @@ func (a *FlowableActivity) SendWALHeartbeat(ctx context.Context) error {
slog.InfoContext(ctx, fmt.Sprintf("sent walheartbeat to peer %v", pgPeer.Name))
}
}
ticker.Reset(sendTimeout)
}
}

Expand Down
4 changes: 1 addition & 3 deletions flow/activities/slot.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ func (a *FlowableActivity) recordSlotSizePeriodically(
return
}

timeout := 5 * time.Minute
ticker := time.NewTicker(timeout)
ticker := time.NewTicker(5 * time.Minute)
defer ticker.Stop()

for {
Expand All @@ -89,6 +88,5 @@ func (a *FlowableActivity) recordSlotSizePeriodically(
case <-ctx.Done():
return
}
ticker.Reset(timeout)
}
}
6 changes: 1 addition & 5 deletions flow/connectors/eventhub/eventhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ func (c *EventHubConnector) processBatch(
batchPerTopic := NewHubBatches(c.hubManager)
toJSONOpts := model.NewToJSONOptions(c.config.UnnestColumns, false)

eventHubFlushTimeout := peerdbenv.PeerDBEventhubFlushTimeoutSeconds()

ticker := time.NewTicker(eventHubFlushTimeout)
ticker := time.NewTicker(peerdbenv.PeerDBEventhubFlushTimeoutSeconds())
defer ticker.Stop()

lastSeenLSN := int64(0)
Expand Down Expand Up @@ -219,8 +217,6 @@ func (c *EventHubConnector) processBatch(
return 0, fmt.Errorf("failed to update last offset: %w", err)
}
}

ticker.Reset(eventHubFlushTimeout)
}
}
}
Expand Down
1 change: 0 additions & 1 deletion flow/connectors/utils/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func HeartbeatRoutine(
case <-ctx.Done():
return
case <-ticker.C:
ticker.Reset(15 * time.Second)
}
}
}()
Expand Down

0 comments on commit 9d4065b

Please sign in to comment.