Add CloseWithReason to agent SignalConn interface (#4492)
This commit is contained in:
@@ -212,6 +212,10 @@ func (w *AgentWorker) Close() error {
|
|||||||
return nil
|
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
|
// Closed returns a channel that is closed when the connection is closed by the server
|
||||||
func (w *AgentWorker) Closed() <-chan struct{} {
|
func (w *AgentWorker) Closed() <-chan struct{} {
|
||||||
return w.fuse.Watch()
|
return w.fuse.Watch()
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ type SignalConn interface {
|
|||||||
ReadWorkerMessage() (*livekit.WorkerMessage, int, error)
|
ReadWorkerMessage() (*livekit.WorkerMessage, int, error)
|
||||||
SetReadDeadline(time.Time) error
|
SetReadDeadline(time.Time) error
|
||||||
Close() error
|
Close() error
|
||||||
|
CloseWithReason(reason string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func JobStatusIsEnded(s livekit.JobStatus) bool {
|
func JobStatusIsEnded(s livekit.JobStatus) bool {
|
||||||
|
|||||||
@@ -32,8 +32,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
pingFrequency = 10 * time.Second
|
pingFrequency = 10 * time.Second
|
||||||
pingTimeout = 2 * time.Second
|
pingTimeout = 2 * time.Second
|
||||||
|
closeWriteTimeout = 5 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
type WSSignalConnection struct {
|
type WSSignalConnection struct {
|
||||||
@@ -56,6 +57,12 @@ func (c *WSSignalConnection) Close() error {
|
|||||||
return c.conn.Close()
|
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 {
|
func (c *WSSignalConnection) SetReadDeadline(deadline time.Time) error {
|
||||||
return c.conn.SetReadDeadline(deadline)
|
return c.conn.SetReadDeadline(deadline)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user