Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

internal/cli: Implement get-stream for job CLI #3410

Merged
merged 2 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changelog/3410.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```release-note:improvement
cli: Implement `waypoint job get-stream` to allow users to attach to running job
streams and receieve output, or get the output from an existing job stream that
already finished.
```
30 changes: 14 additions & 16 deletions internal/cli/job_get_stream.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package cli

import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/hashicorp/waypoint-plugin-sdk/terminal"
"github.com/hashicorp/waypoint/internal/clierrors"
jobstream "github.com/hashicorp/waypoint/internal/jobstream"
"github.com/hashicorp/waypoint/internal/pkg/flag"
pb "github.com/hashicorp/waypoint/pkg/server/gen"
)

type JobGetStreamCommand struct {
Expand All @@ -24,7 +21,6 @@ func (c *JobGetStreamCommand) Run(args []string) int {
); err != nil {
return 1
}
ctx := c.Ctx

var jobId string
if len(c.args) == 0 {
Expand All @@ -34,22 +30,24 @@ func (c *JobGetStreamCommand) Run(args []string) int {
jobId = c.args[0]
}

_, err := c.project.Client().GetJobStream(ctx, &pb.GetJobStreamRequest{
JobId: jobId,
})
if err != nil {
if status.Code(err) == codes.NotFound {
c.ui.Output("Job id not found: %s", clierrors.Humanize(err),
terminal.WithErrorStyle())
return 1
}
sg := c.ui.StepGroup()
defer sg.Wait()

step := sg.Add("Reading job stream (jobId: %s) ...", jobId)
defer step.Abort()

// Ignore the job result for now
_, err := jobstream.Stream(c.Ctx, jobId,
jobstream.WithClient(c.project.Client()),
jobstream.WithUI(c.ui))

if err != nil {
c.ui.Output(clierrors.Humanize(err), terminal.WithErrorStyle())
return 1
}

// TODO(briancain): process and print terminal events like `internal/client/job.go`
c.ui.Output("Job stream is not implemented yet!", terminal.WithWarningStyle())
step.Update("Finished reading job stream")
step.Done()

return 0
}
Expand Down