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

Commit6eb1887

Browse files
authored
Update last connection time on tunnel connections (#401)
* Update last connection time on tunnnel connections* fmt
1 parente641ac5 commit6eb1887

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

‎coder-sdk/agent.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package coder
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"net/http"
7+
)
8+
9+
// UpdateLastConnectionAt updates the last connection at attribute of a workspace.
10+
func (c*DefaultClient)UpdateLastConnectionAt(ctx context.Context,workspaceIDstring)error {
11+
reqURL:=fmt.Sprintf("/api/private/envagent/%s/update-last-connection-at",workspaceID)
12+
resp,err:=c.request(ctx,http.MethodPost,reqURL,nil)
13+
iferr!=nil {
14+
returnerr
15+
}
16+
17+
ifresp.StatusCode!=http.StatusOK {
18+
returnNewHTTPError(resp)
19+
}
20+
21+
returnnil
22+
}

‎coder-sdk/interface.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,7 @@ type Client interface {
250250

251251
// DeleteSatelliteByID deletes a satellite entity from the Coder control plane.
252252
DeleteSatelliteByID(ctx context.Context,idstring)error
253+
254+
// UpdateLastConnectionAt updates the last connection at attribute of a workspace.
255+
UpdateLastConnectionAt(ctx context.Context,workspaceIDstring)error
253256
}

‎internal/cmd/tunnel.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/url"
99
"os"
1010
"strconv"
11+
"time"
1112

1213
"cdr.dev/slog"
1314
"cdr.dev/slog/sloggers/sloghuman"
@@ -130,6 +131,27 @@ func (c *tunnneler) start(ctx context.Context) error {
130131
}
131132
c.log.Debug(ctx,"Connected to workspace!")
132133

134+
sdk,err:=newClient(ctx,false)
135+
iferr!=nil {
136+
returnxerrors.Errorf("getting coder client: %w",err)
137+
}
138+
139+
// regularly update the last connection at
140+
gofunc() {
141+
ticker:=time.NewTicker(time.Minute)
142+
deferticker.Stop()
143+
144+
for {
145+
select {
146+
case<-ctx.Done():
147+
return
148+
case<-ticker.C:
149+
// silently ignore failures so we don't spam the console
150+
_=sdk.UpdateLastConnectionAt(ctx,c.workspaceID)
151+
}
152+
}
153+
}()
154+
133155
// proxy via stdio
134156
ifc.stdio {
135157
gofunc() {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp