mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: replace httpapi.Heartbeat with httpapi.HeartbeatClose (#21676)
Relates to https://github.com/coder/coder/pull/21676 * Replaces all existing usages of `httpapi.Heartbeat` with `httpapi.HeartbeatClose` * Removes `httpapi.HeartbeatClose`
This commit is contained in:
@@ -13,26 +13,7 @@ import (
|
||||
|
||||
const HeartbeatInterval time.Duration = 15 * time.Second
|
||||
|
||||
// Heartbeat loops to ping a WebSocket to keep it alive.
|
||||
// Default idle connection timeouts are typically 60 seconds.
|
||||
// See: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/application-load-balancers.html#connection-idle-timeout
|
||||
func Heartbeat(ctx context.Context, conn *websocket.Conn) {
|
||||
ticker := time.NewTicker(HeartbeatInterval)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
}
|
||||
err := conn.Ping(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Heartbeat loops to ping a WebSocket to keep it alive. It calls `exit` on ping
|
||||
// HeartbeatClose loops to ping a WebSocket to keep it alive. It calls `exit` on ping
|
||||
// failure.
|
||||
func HeartbeatClose(ctx context.Context, logger slog.Logger, exit func(), conn *websocket.Conn) {
|
||||
ticker := time.NewTicker(HeartbeatInterval)
|
||||
|
||||
Reference in New Issue
Block a user