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

Function waitForAgents

scaletest/workspacebuild/run.go:253–290  ·  view source on GitHub ↗
(ctx context.Context, w io.Writer, client *codersdk.Client, workspaceID uuid.UUID)

Source from the content-addressed store, hash-verified

251}
252
253func waitForAgents(ctx context.Context, w io.Writer, client *codersdk.Client, workspaceID uuid.UUID) error {
254 ctx, span := tracing.StartSpan(ctx)
255 defer span.End()
256 _, _ = fmt.Fprint(w, "Waiting for agents to connect...\n\n")
257
258 for {
259 select {
260 case <-ctx.Done():
261 return ctx.Err()
262 default:
263 }
264
265 workspace, err := client.Workspace(ctx, workspaceID)
266 if err != nil {
267 return xerrors.Errorf("fetch workspace: %w", err)
268 }
269
270 ok := true
271 for _, res := range workspace.LatestBuild.Resources {
272 for _, agent := range res.Agents {
273 if agent.Status != codersdk.WorkspaceAgentConnected {
274 ok = false
275 }
276
277 _, _ = fmt.Fprintf(w, "\tAgent %q is %s\n", agent.Name, agent.Status)
278 }
279 }
280 if ok {
281 break
282 }
283
284 _, _ = fmt.Fprintln(w, "")
285 time.Sleep(1 * time.Second)
286 }
287
288 _, _ = fmt.Fprint(w, "\nAgents connected!\n\n")
289 return nil
290}

Callers 1

RunReturningWorkspaceMethod · 0.85

Calls 5

StartSpanFunction · 0.92
ErrMethod · 0.80
WorkspaceMethod · 0.80
DoneMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected