zfscmd

package
v0.7.11 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package zfscmd provides a wrapper around packate os/exec. Functionality provided by the wrapper: - logging start and end of command execution - status report of active commands - prometheus metrics of runtimes

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetJobIDOrDefault

func GetJobIDOrDefault(ctx context.Context, def string) string

func RegisterMetrics

func RegisterMetrics(r prometheus.Registerer)

func WithJobID

func WithJobID(ctx context.Context, jobID string) context.Context

Types

type ActiveCommand

type ActiveCommand struct {
	Path      string
	Args      []string
	StartedAt time.Time
}

type Cmd

type Cmd struct {
	// contains filtered or unexported fields
}

func CommandContext

func CommandContext(ctx context.Context, name string, arg ...string) *Cmd

func (*Cmd) CombinedOutput

func (c *Cmd) CombinedOutput() (o []byte, err error)

err.(*exec.ExitError).Stderr will NOT be set

func (*Cmd) LogError

func (c *Cmd) LogError(err error, debug bool)

func (*Cmd) Output

func (c *Cmd) Output() (o []byte, err error)

err.(*exec.ExitError).Stderr will be set

func (*Cmd) Pipe

func (c *Cmd) Pipe(
	stdin io.ReadCloser, stderr io.Writer, cmds ...[]string,
) (io.ReadCloser, error)

func (*Cmd) Process

func (c *Cmd) Process() *os.Process

Get the underlying os.Process.

Only call this method after a successful call to .Start().

func (*Cmd) Runtime

func (c *Cmd) Runtime() time.Duration

returns 0 if the command did not yet finish

func (*Cmd) SetStdio

func (c *Cmd) SetStdio(stdio Stdio)

func (*Cmd) Start

func (c *Cmd) Start() (err error)

Start the command.

This creates a new trace.WithTask as a child task of the ctx passed to CommandContext. If the process is successfully started (err == nil), it is the CALLER'S RESPONSIBILITY to ensure that the spawned process does not outlive the ctx's trace.Task.

If this method returns an error, the Cmd instance is invalid. Start must not be called repeatedly.

func (*Cmd) StdoutPipeWithErrorBuf

func (c *Cmd) StdoutPipeWithErrorBuf() (p io.ReadCloser, errBuf *circlog.CircularLog, err error)

Careful: err.(*exec.ExitError).Stderr will not be set, even if you don't open an StderrPipe

func (*Cmd) String

func (c *Cmd) String() string

func (*Cmd) TestOnly_ExecCmd

func (c *Cmd) TestOnly_ExecCmd() *exec.Cmd

func (*Cmd) Wait

func (c *Cmd) Wait() (err error)

Blocking wait for the process to exit. May be called concurrently and repeatly (exec.Cmd.Wait() semantics apply).

Only call this method after a successful call to .Start().

func (*Cmd) WaitPipe

func (c *Cmd) WaitPipe() error

func (*Cmd) WithLeftPipe

func (c *Cmd) WithLeftPipe() *Cmd

func (*Cmd) WithLogError

func (c *Cmd) WithLogError(v bool) *Cmd

type Logger

type Logger = logger.Logger

type Report

type Report struct {
	Active []ActiveCommand
}

func GetReport

func GetReport() *Report

type Stdio

type Stdio struct {
	Stdin  io.ReadCloser
	Stdout io.Writer
	Stderr io.Writer
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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