Add CloseWithReason to agent SignalConn interface (#4492)

This commit is contained in:
Théo Monnom
2026-04-28 22:14:06 -07:00
committed by GitHub
parent d7c2daf1ac
commit af1dcc8843
3 changed files with 14 additions and 2 deletions
+4
View File
@@ -212,6 +212,10 @@ func (w *AgentWorker) Close() error {
return nil
}
func (w *AgentWorker) CloseWithReason(_ string) error {
return w.Close()
}
// Closed returns a channel that is closed when the connection is closed by the server
func (w *AgentWorker) Closed() <-chan struct{} {
return w.fuse.Watch()
+1
View File
@@ -59,6 +59,7 @@ type SignalConn interface {
ReadWorkerMessage() (*livekit.WorkerMessage, int, error)
SetReadDeadline(time.Time) error
Close() error
CloseWithReason(reason string) error
}
func JobStatusIsEnded(s livekit.JobStatus) bool {
+9 -2
View File
@@ -32,8 +32,9 @@ import (
)
const (
pingFrequency = 10 * time.Second
pingTimeout = 2 * time.Second
pingFrequency = 10 * time.Second
pingTimeout = 2 * time.Second
closeWriteTimeout = 5 * time.Second
)
type WSSignalConnection struct {
@@ -56,6 +57,12 @@ func (c *WSSignalConnection) Close() error {
return c.conn.Close()
}
func (c *WSSignalConnection) CloseWithReason(reason string) error {
msg := websocket.FormatCloseMessage(websocket.CloseNormalClosure, reason)
_ = c.conn.WriteControl(websocket.CloseMessage, msg, time.Now().Add(closeWriteTimeout))
return c.conn.Close()
}
func (c *WSSignalConnection) SetReadDeadline(deadline time.Time) error {
return c.conn.SetReadDeadline(deadline)
}