runner

package
v0.0.0-...-8023e94 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2021 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package runner provides implementations for running commands in different environments.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchRunner

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

BatchRunner allows many tasks to be run in paralell using a Runner. BatchRunner will give every process the same stderr of your choice but will save the contents of every stdout for later debugging.

func NewBatchRunner

func NewBatchRunner(ctx context.Context, runner Runner, maxBatchSize int) *BatchRunner

NewBatchRunner creates a BatchRunner that can use runner to run many jobs in paralell. At most maxBatchSize jobs will be active at once. Enqueue will block when maxBatchSize is exceeded. When ctx is Done, all jobs will terminate without error.

func (*BatchRunner) Enqueue

func (b *BatchRunner) Enqueue(command []string, stdout, stderr io.Writer, closers ...func())

Enqueue is similair to Run in Runner except that it's async. The call returns immediately and the enqueued command starts running. If however the maximum batch size has been reached Enqueue will block until a new job opens up.

func (*BatchRunner) Wait

func (b *BatchRunner) Wait() error

Wait blocks on all previouslly Enqueued tasks to finish. It is invalid for Enqueue to be called after Wait is called.

type Runner

type Runner interface {
	Run(context.Context, []string, io.Writer, io.Writer) error
}

Runner defines the interface for running commands by many means such as via SSH or via Shell or serial or some other such means.

type SubprocessRunner

type SubprocessRunner struct {
	// Dir is the working directory of the subprocesses; if unspecified, that
	// of the current process will be used.
	Dir string

	// Env is the environment of the subprocess, following the usual convention of a list of
	// strings of the form "<environment variable name>=<value>".
	Env []string
}

SubprocessRunner is a Runner that runs commands as local subprocesses.

func (*SubprocessRunner) Run

func (r *SubprocessRunner) Run(ctx context.Context, command []string, stdout io.Writer, stderr io.Writer) error

Run runs a command until completion or until a context is canceled, in which case the subprocess is killed so that no subprocesses it spun up are orphaned.

func (*SubprocessRunner) RunWithStdin

func (r *SubprocessRunner) RunWithStdin(ctx context.Context, command []string, stdout io.Writer, stderr io.Writer, stdin io.Reader) error

RunWithStdin operates identically to Run, but additionally pipes input to the process via stdin.

Jump to

Keyboard shortcuts

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