This repository was archived by the owner on Aug 30, 2024. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork18
Add ws dials for resource load and ide status#111
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Add WaitForEnvironmentReady utility
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit77d3e643dbbf13a31cf59a52343a3a73f895f231
There are no files selected for viewing
26 changes: 26 additions & 0 deletionscoder-sdk/env.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2,11 +2,13 @@ package coder | ||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"time" | ||
"cdr.dev/coder-cli/internal/x/xjson" | ||
"nhooyr.io/websocket" | ||
"nhooyr.io/websocket/wsjson" | ||
) | ||
// Environment describes a Coder environment | ||
@@ -135,3 +137,27 @@ func (c Client) DialEnvironmentStats(ctx context.Context, envID string) (*websoc | ||
func (c Client) DialResourceLoad(ctx context.Context, envID string) (*websocket.Conn, error) { | ||
cmoog marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
return c.dialWs(ctx, "/api/environments/"+envID+"/watch-resource-load") | ||
} | ||
type buildLogMsg struct { | ||
Type string `json:"type"` | ||
} | ||
// WaitForEnvironmentReady will watch the build log and return when done | ||
func (c Client) WaitForEnvironmentReady(ctx context.Context, env *Environment) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Why does this need the full environment when the above function doesn't? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Ah, good point. | ||
conn, err := c.DialEnvironmentBuildLog(ctx, env.ID) | ||
if err != nil { | ||
return fmt.Errorf("%s: dial build log: %w", env.Name, err) | ||
cmoog marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
} | ||
for { | ||
msg := buildLogMsg{} | ||
err := wsjson.Read(ctx, conn, &msg) | ||
if err != nil { | ||
return fmt.Errorf("%s: reading build log msg: %w", env.Name, err) | ||
} | ||
if msg.Type == "done" { | ||
cmoog marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
return nil | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.