MCPcopy Index your code
hub / github.com/coder/coder / tryPollWorkspaceAutostop

Function tryPollWorkspaceAutostop

cli/ssh.go:1140–1151  ·  view source on GitHub ↗

Attempt to poll workspace autostop. We write a per-workspace lockfile to avoid spamming the user with notifications in case of multiple instances of the CLI running simultaneously.

(ctx context.Context, client *codersdk.Client, workspace codersdk.Workspace)

Source from the content-addressed store, hash-verified

1138// avoid spamming the user with notifications in case of multiple instances
1139// of the CLI running simultaneously.
1140func tryPollWorkspaceAutostop(ctx context.Context, client *codersdk.Client, workspace codersdk.Workspace) (stop func()) {
1141 lock := flock.New(filepath.Join(os.TempDir(), "coder-autostop-notify-"+workspace.ID.String()))
1142 conditionCtx, cancelCondition := context.WithCancel(ctx)
1143 condition := notifyCondition(conditionCtx, client, workspace.ID, lock)
1144 notifier := notify.New(condition, workspacePollInterval, autostopNotifyCountdown)
1145 return func() {
1146 // With many "ssh" processes running, `lock.TryLockContext` can be hanging until the context canceled.
1147 // Without this cancellation, a CLI process with failed remote-forward could be hanging indefinitely.
1148 cancelCondition()
1149 notifier.Close()
1150 }
1151}
1152
1153// Notify the user if the workspace is due to shutdown.
1154func notifyCondition(ctx context.Context, client *codersdk.Client, workspaceID uuid.UUID, lock *flock.Flock) notify.Condition {

Callers 1

sshMethod · 0.85

Calls 6

NewFunction · 0.92
notifyConditionFunction · 0.85
NewMethod · 0.65
TempDirMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected