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)
| 876 | // setLifecycle sets the lifecycle state and notifies the lifecycle loop. |
| 877 | // The state is only updated if it's a valid state transition. |
| 878 | func (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. |
| 902 | func (a *agent) reportConnectionsLoop(ctx context.Context, aAPI proto.DRPCAgentClient28) error { |
no test coverage detected