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

Update last connection time on tunnel connections#401

Merged
f0ssel merged 2 commits intomasterfromf0ssel/ch15443
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletionscoder-sdk/agent.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
package coder

import (
"context"
"fmt"
"net/http"
)

// UpdateLastConnectionAt updates the last connection at attribute of a workspace.
func (c *DefaultClient) UpdateLastConnectionAt(ctx context.Context, workspaceID string) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

That only does so on connection, this will do so continuously for SSH connections and such

kylecarbs reacted with thumbs up emoji
reqURL := fmt.Sprintf("/api/private/envagent/%s/update-last-connection-at", workspaceID)
resp, err := c.request(ctx, http.MethodPost, reqURL, nil)
if err != nil {
return err
}

if resp.StatusCode != http.StatusOK {
return NewHTTPError(resp)
}

return nil
}
3 changes: 3 additions & 0 deletionscoder-sdk/interface.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -250,4 +250,7 @@ type Client interface {

// DeleteSatelliteByID deletes a satellite entity from the Coder control plane.
DeleteSatelliteByID(ctx context.Context,idstring)error

// UpdateLastConnectionAt updates the last connection at attribute of a workspace.
UpdateLastConnectionAt(ctx context.Context,workspaceIDstring)error
}
22 changes: 22 additions & 0 deletionsinternal/cmd/tunnel.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,6 +8,7 @@ import (
"net/url"
"os"
"strconv"
"time"

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

sdk, err := newClient(ctx, false)
if err != nil {
return xerrors.Errorf("getting coder client: %w", err)
}

// regularly update the last connection at
go func() {
ticker := time.NewTicker(time.Minute)
defer ticker.Stop()

for {
select {
case <-ctx.Done():
return
case <-ticker.C:
// silently ignore failures so we don't spam the console
_ = sdk.UpdateLastConnectionAt(ctx, c.workspaceID)
}
}
}()

// proxy via stdio
if c.stdio {
go func() {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp