executor

package
v0.0.0-...-54b4948 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DockerOptions

type DockerOptions struct {
	// Client is the Docker client to use. This is required.
	Client *client.Client
	// Image is the name of the Docker image. This is required.
	Image string
	// Command is the arguments to the command to run in the Docker container.
	// This is required.
	Command []string
	// OS is the operating system that Docker is running in. If unspecified,
	// this defaults to the runtime GOOS.
	OS string
	// Arch is the CPU architecture of the machine that Docker is running in. If
	// unspecified, this defaults to runtime GOARCH.
	Arch string
}

DockerOptions represent options for a Docker runtime executor within a Docker container.

func (*DockerOptions) Validate

func (o *DockerOptions) Validate() error

Validate checks that the required Docker fields are populated. It sets default values where possible.

type Executor

type Executor interface {
	// Args returns the command and the arguments used to create the process.
	Args() []string
	// SetEnv sets the process environment.
	SetEnv([]string)
	// Env returns the process environment.
	Env() []string
	// SetDir sets the process working directory.
	SetDir(string)
	// Dir returns the process working directory.
	Dir() string
	// SetStdin sets the process standard input.
	SetStdin(io.Reader)
	// SetStdout sets the process standard output.
	SetStdout(io.Writer)
	// Stdout returns the process standard output.
	Stdout() io.Writer
	// SetStderr sets the process standard error.
	SetStderr(io.Writer)
	// Stderr returns the process standard error.
	Stderr() io.Writer
	// Start begins execution of the process.
	Start() error
	// Wait waits for the process to complete.
	Wait() error
	// Signal sends a signal to a running process.
	Signal(syscall.Signal) error
	// PID returns the local process ID of the process if it is running or
	// complete. This is not guaranteed to return a valid value for remote
	// executors and will return -1 if it could not be retrieved.
	PID() int
	// ExitCode returns the exit code of a completed process. This will return a
	// non-negative value if it successfully retrieved the exit code. Callers
	// must call Wait before retrieving the exit code.
	ExitCode() int
	// Success returns whether or not the completed process ran successfully.
	// Callers must call Wait before checking for success.
	Success() bool
	// SignalInfo returns information about signals the process has received.
	SignalInfo() (sig syscall.Signal, signaled bool)
	// Close cleans up the executor's resources. Users should not assume the
	// information from the Executor will be accurate after it has been closed.
	Close() error
}

Executor is an interface by which Jasper processes can manipulate and introspect on processes. Implementations are not guaranteed to be thread-safe.

func MakeLocal

func MakeLocal(cmd *exec.Cmd) Executor

MakeLocal wraps an existing local process.

func NewDocker

func NewDocker(ctx context.Context, opts DockerOptions) (Executor, error)

NewDocker returns an Executor that creates a process within a Docker container. Callers are expected to clean up resources by calling Close.

func NewLocal

func NewLocal(ctx context.Context, args []string) Executor

NewLocal returns an Executor that creates processes locally.

func NewSSH

func NewSSH(ctx context.Context, client *cryptossh.Client, session *cryptossh.Session, args []string) Executor

NewSSH returns an Executor that creates processes over SSH. Callers are expected to clean up resources by explicitly calling Close.

func NewSSHBinary

func NewSSHBinary(ctx context.Context, destination string, opts []string, args []string) Executor

NewSSHBinary returns an Executor that creates processes using the SSH binary.

type Status

type Status int

Status represents the current state of the Executor.

const (
	// Unknown means the process is in an unknown or invalid state.
	Unknown Status = iota
	// Unstarted means that the Executor has not yet started running the
	// process.
	Unstarted Status = iota
	// Running means that the Executor has started running the process.
	Running Status = iota
	// Exited means the Executor has finished running the process.
	Exited Status = iota
	// Closed means the Executor has cleaned up its resources and further
	// requests cannot be made.
	Closed Status = iota
)

func (Status) After

func (s Status) After(other Status) bool

After returns whether or not the given state occurs before the current state.

func (Status) AfterInclusive

func (s Status) AfterInclusive(other Status) bool

AfterInclusive is the same as After but also returns true if the given state is identical to the current state.

func (Status) Before

func (s Status) Before(other Status) bool

Before returns whether or not the given state occurs before the current state.

func (Status) BeforeInclusive

func (s Status) BeforeInclusive(other Status) bool

BeforeInclusive is the same as Before but also returns true if the given state is identical to the current state.

func (Status) Between

func (s Status) Between(lower Status, upper Status) bool

Between returns whether or not the state occurs after the given lower state and after the given upper state.

func (Status) BetweenInclusive

func (s Status) BetweenInclusive(lower Status, upper Status) bool

BetweenInclusive is the same as Between but also returns true if the given state is identical to the given lower or upper state.

func (Status) String

func (s Status) String() string

Jump to

Keyboard shortcuts

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