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

Method wait

cli/cliui/agent.go:124–157  ·  view source on GitHub ↗

wait runs the main state machine loop.

(ctx context.Context, agent codersdk.WorkspaceAgent, fetchedAgent chan fetchAgentResult)

Source from the content-addressed store, hash-verified

122
123// wait runs the main state machine loop.
124func (aw *agentWaiter) wait(ctx context.Context, agent codersdk.WorkspaceAgent, fetchedAgent chan fetchAgentResult) error {
125 var err error
126 // Track whether we've gone through a wait state, which determines if we
127 // should show startup logs when connected.
128 waitedForConnection := false
129
130 for {
131 // It doesn't matter if we're connected or not, if the agent is
132 // shutting down, we don't know if it's coming back.
133 if agent.LifecycleState.ShuttingDown() {
134 return errAgentShuttingDown
135 }
136
137 switch agent.Status {
138 case codersdk.WorkspaceAgentConnecting, codersdk.WorkspaceAgentTimeout:
139 agent, err = aw.waitForConnection(ctx, agent)
140 if err != nil {
141 return err
142 }
143 // Since we were waiting for the agent to connect, also show
144 // startup logs if applicable.
145 waitedForConnection = true
146
147 case codersdk.WorkspaceAgentConnected:
148 return aw.handleConnected(ctx, agent, waitedForConnection, fetchedAgent)
149
150 case codersdk.WorkspaceAgentDisconnected:
151 agent, waitedForConnection, err = aw.waitForReconnection(ctx, agent)
152 if err != nil {
153 return err
154 }
155 }
156 }
157}
158
159// waitForConnection handles the Connecting/Timeout states.
160// Returns when agent transitions to Connected or Disconnected.

Callers 1

AgentFunction · 0.95

Calls 4

waitForConnectionMethod · 0.95
handleConnectedMethod · 0.95
waitForReconnectionMethod · 0.95
ShuttingDownMethod · 0.80

Tested by

no test coverage detected