File tree 1 file changed +26
-0
lines changed
1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -2,11 +2,13 @@ package coder
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
5
6
"net/http"
6
7
"time"
7
8
8
9
"cdr.dev/coder-cli/internal/x/xjson"
9
10
"nhooyr.io/websocket"
11
+ "nhooyr.io/websocket/wsjson"
10
12
)
11
13
12
14
// Environment describes a Coder environment
@@ -135,3 +137,27 @@ func (c Client) DialEnvironmentStats(ctx context.Context, envID string) (*websoc
135
137
func (c Client ) DialResourceLoad (ctx context.Context , envID string ) (* websocket.Conn , error ) {
136
138
return c .dialWs (ctx , "/api/environments/" + envID + "/watch-resource-load" )
137
139
}
140
+
141
+ type buildLogMsg struct {
142
+ Type string `json:"type"`
143
+ }
144
+
145
+ // WaitForEnvironmentReady will watch the build log and return when done
146
+ func (c Client ) WaitForEnvironmentReady (ctx context.Context , env * Environment ) error {
147
+ conn , err := c .DialEnvironmentBuildLog (ctx , env .ID )
148
+ if err != nil {
149
+ return fmt .Errorf ("%s: dial build log: %w" , env .Name , err )
150
+ }
151
+
152
+ for {
153
+ msg := buildLogMsg {}
154
+ err := wsjson .Read (ctx , conn , & msg )
155
+ if err != nil {
156
+ return fmt .Errorf ("%s: reading build log msg: %w" , env .Name , err )
157
+ }
158
+
159
+ if msg .Type == "done" {
160
+ return nil
161
+ }
162
+ }
163
+ }
You can’t perform that action at this time.
0 commit comments