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

Commitac39d3c

Browse files
authored
Merge pull request#111 from cdr/stress-sdk-2
Add ws dials for resource load and ide status
2 parents8022bfc +89752df commitac39d3c

File tree

1 file changed

+59
-3
lines changed

1 file changed

+59
-3
lines changed

‎coder-sdk/env.go

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import (
66
"time"
77

88
"cdr.dev/coder-cli/internal/x/xjson"
9+
"golang.org/x/xerrors"
910
"nhooyr.io/websocket"
11+
"nhooyr.io/websocket/wsjson"
1012
)
1113

1214
// Environment describes a Coder environment
@@ -81,14 +83,14 @@ type CreateEnvironmentRequest struct {
8183

8284
// CreateEnvironment sends a request to create an environment.
8385
func (cClient)CreateEnvironment(ctx context.Context,orgIDstring,reqCreateEnvironmentRequest) (*Environment,error) {
84-
varenv*Environment
86+
varenvEnvironment
8587
err:=c.requestBody(
8688
ctx,
8789
http.MethodPost,"/api/orgs/"+orgID+"/environments",
8890
req,
89-
env,
91+
&env,
9092
)
91-
returnenv,err
93+
return&env,err
9294
}
9395

9496
// EnvironmentsByOrganization gets the list of environments owned by the given user.
@@ -119,6 +121,11 @@ func (c Client) DialWsep(ctx context.Context, env *Environment) (*websocket.Conn
119121
returnc.dialWs(ctx,"/proxy/environments/"+env.ID+"/wsep")
120122
}
121123

124+
// DialIDEStatus opens a websocket connection for cpu load metrics on the environment
125+
func (cClient)DialIDEStatus(ctx context.Context,envIDstring) (*websocket.Conn,error) {
126+
returnc.dialWs(ctx,"/proxy/environments/"+envID+"/ide/api/status")
127+
}
128+
122129
// DialEnvironmentBuildLog opens a websocket connection for the environment build log messages
123130
func (cClient)DialEnvironmentBuildLog(ctx context.Context,envIDstring) (*websocket.Conn,error) {
124131
returnc.dialWs(ctx,"/api/environments/"+envID+"/watch-update")
@@ -128,3 +135,52 @@ func (c Client) DialEnvironmentBuildLog(ctx context.Context, envID string) (*web
128135
func (cClient)DialEnvironmentStats(ctx context.Context,envIDstring) (*websocket.Conn,error) {
129136
returnc.dialWs(ctx,"/api/environments/"+envID+"/watch-stats")
130137
}
138+
139+
// DialResourceLoad opens a websocket connection for cpu load metrics on the environment
140+
func (cClient)DialResourceLoad(ctx context.Context,envIDstring) (*websocket.Conn,error) {
141+
returnc.dialWs(ctx,"/api/environments/"+envID+"/watch-resource-load")
142+
}
143+
144+
// BuildLogType describes the type of an event.
145+
typeBuildLogTypestring
146+
147+
const (
148+
// BuildLogTypeStart signals that a new build log has begun.
149+
BuildLogTypeStartBuildLogType="start"
150+
// BuildLogTypeStage is a stage-level event for an environment.
151+
// It can be thought of as a major step in the environment's
152+
// lifecycle.
153+
BuildLogTypeStageBuildLogType="stage"
154+
// BuildLogTypeError describes an error that has occurred.
155+
BuildLogTypeErrorBuildLogType="error"
156+
// BuildLogTypeSubstage describes a subevent that occurs as
157+
// part of a stage. This can be the output from a user's
158+
// personalization script, or a long running command.
159+
BuildLogTypeSubstageBuildLogType="substage"
160+
// BuildLogTypeDone signals that the build has completed.
161+
BuildLogTypeDoneBuildLogType="done"
162+
)
163+
164+
typebuildLogMsgstruct {
165+
TypeBuildLogType`json:"type"`
166+
}
167+
168+
// WaitForEnvironmentReady will watch the build log and return when done
169+
func (cClient)WaitForEnvironmentReady(ctx context.Context,env*Environment)error {
170+
conn,err:=c.DialEnvironmentBuildLog(ctx,env.ID)
171+
iferr!=nil {
172+
returnxerrors.Errorf("%s: dial build log: %w",env.Name,err)
173+
}
174+
175+
for {
176+
msg:=buildLogMsg{}
177+
err:=wsjson.Read(ctx,conn,&msg)
178+
iferr!=nil {
179+
returnxerrors.Errorf("%s: reading build log msg: %w",env.Name,err)
180+
}
181+
182+
ifmsg.Type==BuildLogTypeDone {
183+
returnnil
184+
}
185+
}
186+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp