jobstream

package
v0.11.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2023 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package jobstream has helpers for working more easily with the GetJobStream endpoint, such as handling the full lifecycle of GetJobStream to a UI implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Stream

func Stream(ctx context.Context, jobId string, opts ...Option) (*pb.Job_Result, error)

Stream a single job and return the result from that job. This function blocks until the job reaches a terminal state (success or fail).

Types

type Option

type Option func(s *stream) error

Option specifies an option for streaming.

func WithCancelOnError

func WithCancelOnError(v bool) Option

WithCancelOnError causes the job being watched to be canceled (with CancelJob) if the streamer exits unsuccessfully. Defaults to false.

func WithClient

func WithClient(client pb.WaypointClient) Option

Set the client for the stream watcher. This is required.

func WithIgnoreTerminal

func WithIgnoreTerminal(v bool) Option

WithIgnoreTerminal ignores the terminal events from the job. Other UI output may happen such as queue delays but the actual terminal events are hidden.

func WithLogger

func WithLogger(log hclog.Logger) Option

Set a logger for the stream watcher.

func WithStateCh

func WithStateCh(v chan<- pb.Job_State) Option

WithStateCh sets a channel that is sent all the job state changes. This must not block. If the channel blocks, the entire stream watcher may be blocked.

func WithUI

func WithUI(ui terminal.UI) Option

Set the UI for all user-facing output to be sent to.

type UI

type UI struct {
	// The underlying UI that will be written to.
	UI terminal.UI

	// Log for unknown events and other diagnostics.
	Log hclog.Logger
	// contains filtered or unexported fields
}

UI converts a stream of terminal events from a job stream into stateful function calls to a terminal.UI implementation.

func (*UI) Write

func (s *UI) Write(events []*pb.GetJobStreamResponse_Terminal_Event) error

Write processes the given events and converts them to calls to UI. The order of the events matter because events are stateful: some events start a table, some end it, etc.

TODO(mitchellh): This was extracted directly from internal/client. It had no tests there and it still has no tests here. We should test this eventually and it should be pretty easy to do so!

Directories

Path Synopsis
This package implements some of the tests for the jobstream package.
This package implements some of the tests for the jobstream package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL