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

Add ws dials for resource load and ide status#111

Merged
f0ssel merged 3 commits intomasterfromstress-sdk-2
Sep 4, 2020
Merged
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Add WaitForEnvironmentReady utility
  • Loading branch information
@f0ssel
f0ssel committedSep 4, 2020
commit77d3e643dbbf13a31cf59a52343a3a73f895f231
26 changes: 26 additions & 0 deletionscoder-sdk/env.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand DownExpand Up@@ -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) {
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The 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)
}

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" {
return nil
}
}
}

[8]ページ先頭

©2009-2025 Movatter.jp