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

Method setLifecycle

agent/agent.go:878–899  ·  view source on GitHub ↗

setLifecycle sets the lifecycle state and notifies the lifecycle loop. The state is only updated if it's a valid state transition.

(state codersdk.WorkspaceAgentLifecycle)

Source from the content-addressed store, hash-verified

876// setLifecycle sets the lifecycle state and notifies the lifecycle loop.
877// The state is only updated if it's a valid state transition.
878func (a *agent) setLifecycle(state codersdk.WorkspaceAgentLifecycle) {
879 report := agentsdk.PostLifecycleRequest{
880 State: state,
881 ChangedAt: dbtime.Now(),
882 }
883
884 a.lifecycleMu.Lock()
885 lastReport := a.lifecycleStates[len(a.lifecycleStates)-1]
886 if slices.Index(codersdk.WorkspaceAgentLifecycleOrder, lastReport.State) >= slices.Index(codersdk.WorkspaceAgentLifecycleOrder, report.State) {
887 a.logger.Warn(context.Background(), "attempted to set lifecycle state to a previous state", slog.F("last", lastReport), slog.F("current", report))
888 a.lifecycleMu.Unlock()
889 return
890 }
891 a.lifecycleStates = append(a.lifecycleStates, report)
892 a.logger.Debug(context.Background(), "set lifecycle state", slog.F("current", report), slog.F("last", lastReport))
893 a.lifecycleMu.Unlock()
894
895 select {
896 case a.lifecycleUpdate <- struct{}{}:
897 default:
898 }
899}
900
901// reportConnectionsLoop reports connections to the agent for auditing.
902func (a *agent) reportConnectionsLoop(ctx context.Context, aAPI proto.DRPCAgentClient28) error {

Callers 2

handleManifestMethod · 0.95
CloseMethod · 0.95

Calls 3

NowFunction · 0.92
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected