runner

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package runner holds the building blocks for cmd runner.

Index

Constants

This section is empty.

Variables

View Source
var ErrNonUniqueProcessTypeName = errors.New("non unique process type name")

ErrNonUniqueProcessTypeName is returned when starting the runner, it detects that its configuration possesses non unique process type names after it normalizes them.

Functions

This section is empty.

Types

type LogMessage added in v1.0.2

type LogMessage struct {
	PaddedName string `json:"paddedName"`
	Name       string `json:"name"`
	Line       string `json:"line"`
}

LogMessage broadcasted through websocket.

type ProcessType

type ProcessType struct {
	// Name of the process type. If the name is prefixed with "build" it is
	// executed before the others.
	Name string `json:"name"`

	// Cmd are the commands necessary to start the process type. They are
	// executed in sequence, each its own separated shell. No state is
	// shared across commands.
	Cmd []string `json:"cmd"`

	// WaitBefore is the network address or process type name that the
	// process type waits to be available before initiating the process type
	// start.
	WaitBefore string `json:"waitbefore,omitempty"`

	// WaitFor is the network address or process type name that the process
	// type waits to be available before finalizing the start.
	WaitFor string `json:"waitfor,omitempty"`

	// Restart is the flag that forces the process type to restart. It means
	// that all steps are executed upon restart. This option does not apply
	// to build steps.
	//
	// - yes|always: alway restart the process type.
	// - no|<empty>: restart the process type on rebuild.
	// - on-failure|fail: restart the process type if any of the steps fail.
	// - temporary|tmp: start the process once and skip restart on rebuild.
	// Temporary processes do not show up in the discovery service.
	Restart RestartMode `json:"restart,omitempty"`

	// Group defines to which supervisor group this process type belongs.
	// Group is useful to contain restart to a subset of the process types.
	Group string

	// Sticky processes are not interrupted by filesystem events.
	Sticky bool

	// Optional processes are the ones skipped by default during start. The
	// user must explicitly tell this process to start.
	Optional bool
}

ProcessType is the piece of software you want to start. Cmd accepts multiple commands. All commands are executed in order of declaration. The last command is considered the call which activates the process type. If WaitBefore is defined, it will wait for network readiness on the defined target before executing the first command. If WaitFor is defined, it will wait for network readiness on the defined target before executing the last command. Process types named with prefix "build" are special, they are executed first in preparation for all other process types, upon their completion the application initialized.

type RestartMode

type RestartMode string

RestartMode defines if a process should restart itself.

const (
	Always    RestartMode = "yes"
	OnFailure RestartMode = "fail"
	Temporary RestartMode = "temporary"
	Loop      RestartMode = "loop"
	Never     RestartMode = ""
)

Restart modes

func ParseRestartMode

func ParseRestartMode(m string) RestartMode

ParseRestartMode takes a string and converts to RestartMode. If the parsing fails, it silently defaults to Never.

type Runner

type Runner struct {
	// WorkDir is the working directory from which all commands are going
	// to be executed.
	WorkDir string `json:"workdir,omitempty"`

	// Observables are the filepath.Match() patterns used to scan for files
	// with changes. File patterns preceded with exclamation mark (!) will
	// not trigger builds.
	Observables []string `json:"observables,omitempty"`

	// SkipDirs are the directory names that are ignored during changed file
	// scanning.
	SkipDirs []string `json:"skipdir,omitempty"`

	// Processes is the list of processes necessary to start this
	// application.
	Processes []*ProcessType `json:"procs"`

	// BasePort is the IP port number used to calculate an IP port for each
	// process type and set to its $PORT environment variable. Build
	// processes do not earn an IP port.
	BasePort int

	// Formation allows to start more than one process type each time. Each
	// start will yield its own exclusive $PORT. Formation does not apply
	// to build process types.
	Formation map[string]int // map of process type name and count

	// BaseEnvironment is the set of environment variables loaded into
	// the service.
	BaseEnvironment []string

	// ServiceDiscoveryAddr is the net.Listen address used to bind the
	// service discovery service. Set to empty to disable it. If activated
	// this address is passed to the processes through the environment
	// variable named "DISCOVERY".
	ServiceDiscoveryAddr string
	// contains filtered or unexported fields
}

Runner defines how this application should be started.

func New

func New() *Runner

New creates a new runner ready to use.

func (*Runner) Start

func (r *Runner) Start(rootCtx context.Context) error

Start initiates the application.

Jump to

Keyboard shortcuts

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