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

Function notifyCondition

cli/ssh.go:1154–1188  ·  view source on GitHub ↗

Notify the user if the workspace is due to shutdown.

(ctx context.Context, client *codersdk.Client, workspaceID uuid.UUID, lock *flock.Flock)

Source from the content-addressed store, hash-verified

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 {
1155 return func(now time.Time) (deadline time.Time, callback func()) {
1156 // Keep trying to regain the lock.
1157 locked, err := lock.TryLockContext(ctx, workspacePollInterval)
1158 if err != nil || !locked {
1159 return time.Time{}, nil
1160 }
1161
1162 ws, err := client.Workspace(ctx, workspaceID)
1163 if err != nil {
1164 return time.Time{}, nil
1165 }
1166
1167 if ptr.NilOrZero(ws.TTLMillis) {
1168 return time.Time{}, nil
1169 }
1170
1171 deadline = ws.LatestBuild.Deadline.Time
1172 callback = func() {
1173 ttl := deadline.Sub(now)
1174 var title, body string
1175 if ttl > time.Minute {
1176 title = fmt.Sprintf(`Workspace %s stopping soon`, ws.Name)
1177 body = fmt.Sprintf(
1178 `Your Coder workspace %s is scheduled to stop in %.0f mins`, ws.Name, ttl.Minutes())
1179 } else {
1180 title = fmt.Sprintf("Workspace %s stopping!", ws.Name)
1181 body = fmt.Sprintf("Your Coder workspace %s is stopping any time now!", ws.Name)
1182 }
1183 // notify user with a native system notification (best effort)
1184 _ = beeep.Notify(title, body, "")
1185 }
1186 return deadline.Truncate(time.Minute), callback
1187 }
1188}
1189
1190// Verify if the user workspace is outdated and prepare an actionable message for user.
1191func verifyWorkspaceOutdated(client *codersdk.Client, workspace codersdk.Workspace) (string, bool) {

Callers 1

tryPollWorkspaceAutostopFunction · 0.85

Calls 3

NilOrZeroFunction · 0.92
WorkspaceMethod · 0.80
NotifyMethod · 0.45

Tested by

no test coverage detected