Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commit3ba357f

Browse files
committed
Add heartbeat
1 parent6f726cd commit3ba357f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎cmd/coder/shell.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"golang.org/x/sys/unix"
1313
"golang.org/x/time/rate"
1414
"golang.org/x/xerrors"
15+
"nhooyr.io/websocket"
1516

1617
"go.coder.com/cli"
1718
"go.coder.com/flog"
@@ -126,6 +127,7 @@ func runCommand(ctx context.Context, envName string, command string, args []stri
126127
iferr!=nil {
127128
returnerr
128129
}
130+
goheatbeat(ctx,conn,15*time.Second)
129131

130132
execer:=wsep.RemoteExecer(conn)
131133
process,err:=execer.Start(ctx, wsep.Command{
@@ -172,4 +174,21 @@ func runCommand(ctx context.Context, envName string, command string, args []stri
172174
returnerr
173175
}
174176

177+
funcheatbeat(ctx context.Context,c*websocket.Conn,interval time.Duration) {
178+
ticker:=time.NewTicker(interval)
179+
deferticker.Stop()
180+
181+
for {
182+
select {
183+
case<-ctx.Done():
184+
return
185+
case<-ticker.C:
186+
err:=c.Ping(ctx)
187+
iferr!=nil {
188+
flog.Error("failed to ping websocket: %v",err)
189+
}
190+
}
191+
}
192+
}
193+
175194
constsshActivityName="ssh"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp