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

Function ActivityBumpWorkspace

coderd/workspacestats/activitybump.go:54–78  ·  view source on GitHub ↗

ActivityBumpWorkspace automatically bumps the workspace's auto-off timer if it is set to expire soon. The deadline will be bumped by 1 hour*. If the bump crosses over an autostart time, the workspace will be bumped by the workspace ttl instead. If nextAutostart is the zero value or in the past, the

(ctx context.Context, log slog.Logger, db database.Store, workspaceID uuid.UUID, nextAutostart time.Time, reason ActivityBumpReason)

Source from the content-addressed store, hash-verified

52// span more than 1 day. This will force the workspace to restart and reset the deadline
53// each morning when it autostarts.
54func ActivityBumpWorkspace(ctx context.Context, log slog.Logger, db database.Store, workspaceID uuid.UUID, nextAutostart time.Time, reason ActivityBumpReason) {
55 // We set a short timeout so if the app is under load, these
56 // low priority operations fail first.
57 ctx, cancel := context.WithTimeout(ctx, time.Second*15)
58 defer cancel()
59 err := db.ActivityBumpWorkspace(ctx, database.ActivityBumpWorkspaceParams{
60 NextAutostart: nextAutostart.UTC(),
61 WorkspaceID: workspaceID,
62 })
63 if err != nil {
64 if !xerrors.Is(err, context.Canceled) && !database.IsQueryCanceledError(err) {
65 // Bump will fail if the context is canceled, but this is ok.
66 log.Error(ctx, "activity bump failed", slog.Error(err),
67 slog.F("workspace_id", workspaceID),
68 slog.F("reason", reason),
69 )
70 }
71 return
72 }
73
74 log.Debug(ctx, "bumped deadline from activity",
75 slog.F("workspace_id", workspaceID),
76 slog.F("reason", reason),
77 )
78}

Callers 5

UpdateAppStatusMethod · 0.92
trackWorkspaceUsageMethod · 0.92
TestPrebuildActivityBumpFunction · 0.92
ReportAgentStatsMethod · 0.85

Calls 4

IsQueryCanceledErrorFunction · 0.92
ActivityBumpWorkspaceMethod · 0.65
IsMethod · 0.45
ErrorMethod · 0.45

Tested by 2

TestPrebuildActivityBumpFunction · 0.74