Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 89752df

Browse files
committed
Add build log types
1 parent 77d3e64 commit 89752df

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

coder-sdk/env.go

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

33
import (
44
"context"
5-
"fmt"
65
"net/http"
76
"time"
87

98
"cdr.dev/coder-cli/internal/x/xjson"
9+
"golang.org/x/xerrors"
1010
"nhooyr.io/websocket"
1111
"nhooyr.io/websocket/wsjson"
1212
)
@@ -138,25 +138,45 @@ func (c Client) DialResourceLoad(ctx context.Context, envID string) (*websocket.
138138
return c.dialWs(ctx, "/api/environments/"+envID+"/watch-resource-load")
139139
}
140140

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+
141161
type buildLogMsg struct {
142-
Type string `json:"type"`
162+
Type BuildLogType `json:"type"`
143163
}
144164

145165
// WaitForEnvironmentReady will watch the build log and return when done
146166
func (c Client) WaitForEnvironmentReady(ctx context.Context, env *Environment) error {
147167
conn, err := c.DialEnvironmentBuildLog(ctx, env.ID)
148168
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)
150170
}
151171

152172
for {
153173
msg := buildLogMsg{}
154174
err := wsjson.Read(ctx, conn, &msg)
155175
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)
157177
}
158178

159-
if msg.Type == "done" {
179+
if msg.Type == BuildLogTypeDone {
160180
return nil
161181
}
162182
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy