waitForAgentCond uses the watch workspace API to update the agent information until the condition is met.
(ctx context.Context, client *codersdk.Client, workspace codersdk.Workspace, workspaceAgent codersdk.WorkspaceAgent, cond func(codersdk.WorkspaceAgent) bool)
| 522 | // waitForAgentCond uses the watch workspace API to update the agent information |
| 523 | // until the condition is met. |
| 524 | func waitForAgentCond(ctx context.Context, client *codersdk.Client, workspace codersdk.Workspace, workspaceAgent codersdk.WorkspaceAgent, cond func(codersdk.WorkspaceAgent) bool) (codersdk.Workspace, codersdk.WorkspaceAgent, error) { |
| 525 | ctx, cancel := context.WithCancel(ctx) |
| 526 | defer cancel() |
| 527 | |
| 528 | if cond(workspaceAgent) { |
| 529 | return workspace, workspaceAgent, nil |
| 530 | } |
| 531 | |
| 532 | wc, err := client.WatchWorkspace(ctx, workspace.ID) |
| 533 | if err != nil { |
| 534 | return workspace, workspaceAgent, xerrors.Errorf("watch workspace: %w", err) |
| 535 | } |
| 536 | |
| 537 | for workspace = range wc { |
| 538 | workspaceAgent, _, err = getWorkspaceAgent(workspace, workspaceAgent.Name) |
| 539 | if err != nil { |
| 540 | return workspace, workspaceAgent, xerrors.Errorf("get workspace agent: %w", err) |
| 541 | } |
| 542 | if cond(workspaceAgent) { |
| 543 | return workspace, workspaceAgent, nil |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | return workspace, workspaceAgent, xerrors.New("watch workspace: unexpected closed channel") |
| 548 | } |
| 549 | |
| 550 | // isWindowsAbsPath does a simplistic check for if the path is an absolute path |
| 551 | // on Windows. Drive letter or preceding `\` is interpreted as absolute. |
no test coverage detected