@@ -2,11 +2,11 @@ package coder
2
2
3
3
import (
4
4
"context"
5
- "fmt"
6
5
"net/http"
7
6
"time"
8
7
9
8
"cdr.dev/coder-cli/internal/x/xjson"
9
+ "golang.org/x/xerrors"
10
10
"nhooyr.io/websocket"
11
11
"nhooyr.io/websocket/wsjson"
12
12
)
@@ -138,25 +138,45 @@ func (c Client) DialResourceLoad(ctx context.Context, envID string) (*websocket.
138
138
return c .dialWs (ctx , "/api/environments/" + envID + "/watch-resource-load" )
139
139
}
140
140
141
+ // BuildLogType describes the type of an event.
142
+ type BuildLogType string
143
+
144
+ const (
145
+ // BuildLogTypeStart signals that a new build log has begun.
146
+ BuildLogTypeStart BuildLogType = "start"
147
+ // BuildLogTypeStage is a stage-level event for an environment.
148
+ // It can be thought of as a major step in the environment's
149
+ // lifecycle.
150
+ BuildLogTypeStage BuildLogType = "stage"
151
+ // BuildLogTypeError describes an error that has occurred.
152
+ BuildLogTypeError BuildLogType = "error"
153
+ // BuildLogTypeSubstage describes a subevent that occurs as
154
+ // part of a stage. This can be the output from a user's
155
+ // personalization script, or a long running command.
156
+ BuildLogTypeSubstage BuildLogType = "substage"
157
+ // BuildLogTypeDone signals that the build has completed.
158
+ BuildLogTypeDone BuildLogType = "done"
159
+ )
160
+
141
161
type buildLogMsg struct {
142
- Type string `json:"type"`
162
+ Type BuildLogType `json:"type"`
143
163
}
144
164
145
165
// WaitForEnvironmentReady will watch the build log and return when done
146
166
func (c Client ) WaitForEnvironmentReady (ctx context.Context , env * Environment ) error {
147
167
conn , err := c .DialEnvironmentBuildLog (ctx , env .ID )
148
168
if err != nil {
149
- return fmt .Errorf ("%s: dial build log: %w" , env .Name , err )
169
+ return xerrors .Errorf ("%s: dial build log: %w" , env .Name , err )
150
170
}
151
171
152
172
for {
153
173
msg := buildLogMsg {}
154
174
err := wsjson .Read (ctx , conn , & msg )
155
175
if err != nil {
156
- return fmt .Errorf ("%s: reading build log msg: %w" , env .Name , err )
176
+ return xerrors .Errorf ("%s: reading build log msg: %w" , env .Name , err )
157
177
}
158
178
159
- if msg .Type == "done" {
179
+ if msg .Type == BuildLogTypeDone {
160
180
return nil
161
181
}
162
182
}
0 commit comments