Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commit77d3e64

Browse files
committed
Add WaitForEnvironmentReady utility
1 parentba5d4b8 commit77d3e64

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

‎coder-sdk/env.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package coder
22

33
import (
44
"context"
5+
"fmt"
56
"net/http"
67
"time"
78

89
"cdr.dev/coder-cli/internal/x/xjson"
910
"nhooyr.io/websocket"
11+
"nhooyr.io/websocket/wsjson"
1012
)
1113

1214
// Environment describes a Coder environment
@@ -135,3 +137,27 @@ func (c Client) DialEnvironmentStats(ctx context.Context, envID string) (*websoc
135137
func (cClient)DialResourceLoad(ctx context.Context,envIDstring) (*websocket.Conn,error) {
136138
returnc.dialWs(ctx,"/api/environments/"+envID+"/watch-resource-load")
137139
}
140+
141+
typebuildLogMsgstruct {
142+
Typestring`json:"type"`
143+
}
144+
145+
// WaitForEnvironmentReady will watch the build log and return when done
146+
func (cClient)WaitForEnvironmentReady(ctx context.Context,env*Environment)error {
147+
conn,err:=c.DialEnvironmentBuildLog(ctx,env.ID)
148+
iferr!=nil {
149+
returnfmt.Errorf("%s: dial build log: %w",env.Name,err)
150+
}
151+
152+
for {
153+
msg:=buildLogMsg{}
154+
err:=wsjson.Read(ctx,conn,&msg)
155+
iferr!=nil {
156+
returnfmt.Errorf("%s: reading build log msg: %w",env.Name,err)
157+
}
158+
159+
ifmsg.Type=="done" {
160+
returnnil
161+
}
162+
}
163+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp