utils

package
v0.0.0-...-d2e7f13 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// EventRunRequested run requested
	EventRunRequested = "run.requested"
	// EventRunStarted run started
	EventRunStarted = "run.started"
	// EventRunError start failed
	EventRunError = "run.error"
	// EventRunFail ran but the command failed
	EventRunFail = "run.fail"
	// EventRunWaitError ran but failed on wait
	EventRunWaitError = "run.wait.error"
	// EventRunSuccess ran with success
	EventRunSuccess = "run.success"
	// EventRunTimeout run timed out
	EventRunTimeout = "run.timeout"
	// EventRunningProbe announces probing
	EventRunningProbe = "run.probing"
)
View Source
const (
	// FldStep is a logger field
	FldStep = "Step"
)

Variables

View Source
var (
	// Version is trackman version
	Version = "0.0.1"
	// Channel is the build channel
	Channel = "dev"
)
View Source
var (
	// CtxSpinner is the key to a spinner on the context
	CtxSpinner = CtxKey{1}
)

Functions

func CloseAllFiles

func CloseAllFiles()

CloseAllFiles closes all files in fileRegister

func ExpandEnvVars

func ExpandEnvVars(ctx context.Context, value string) (string, error)

ExpandEnvVars replaces any reference to environment variables with the OS envs

func NewLogger

func NewLogger(baseDefinition *LogDefinition, loggingContext *LoggingContext) (*logrus.Logger, error)

NewLogger creates a new logger instance and sets the right log level based

func PrintError

func PrintError(format string, a ...interface{})

PrintError prints an error to the console in red

Types

type CtxKey

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

CtxKey is a context key

type Event

type Event struct {
	Name    string
	Payload Payload
}

Event is a simple event

func NewEvent

func NewEvent(spinner *Spinner, name string, extras interface{}) *Event

NewEvent creates a new event

type LogDefinition

type LogDefinition struct {
	Level       string `yaml:"level" json:"level"`
	Type        string `yaml:"type" json:"type"`
	Format      string `yaml:"format" json:"format"`
	Destination string `yaml:"destination" json:"destination"`
}

LogDefinition is used to define where a logger should log to

func DefaultLogDefinition

func DefaultLogDefinition(baseDefinition *LogDefinition) *LogDefinition

DefaultLogDefinition returns a LogDefintion based on the given base if the base is nil it creates a new one if not nil, it fills the empty values with the defaults

type LogWriter

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

LogWriter implements io.Writer so it can be used to dump a process output but links it to logrus

func NewLogWriter

func NewLogWriter(ctx context.Context, logger *logrus.Logger, level logrus.Level) *LogWriter

NewLogWriter creates a new LogWriter

func (*LogWriter) Write

func (l *LogWriter) Write(b []byte) (int, error)

Write implements io.Writer

type LoggingContext

type LoggingContext struct {
	Workflow *Workflow
	Step     *Step
}

LoggingContext is a structure that holds workflow and step and is used to determine log configuration

func NewLoggingContext

func NewLoggingContext(workflow *Workflow, step *Step) *LoggingContext

NewLoggingContext creates a new logging context. Da

type Payload

type Payload struct {
	EventUUID string
	Spinner   *Spinner
	Step      Step
	Extras    interface{}
}

Payload is what's sent over to a notifier

type Preflight

type Preflight struct {
	Command string         `yaml:"command" json:"command"`
	Message string         `yaml:"message" json:"message"`
	Workdir string         `yaml:"workdir" json:"workdir"`
	Timeout *time.Duration `yaml:"timeout" json:"timeout"`
	// contains filtered or unexported fields
}

Preflight is a check that runs at the beginning of the workflow

func (*Preflight) Run

func (p *Preflight) Run(ctx context.Context) error

Run runs the preflight

type Probe

type Probe struct {
	Command string `yaml:"command" json:"command"`
	Workdir string `yaml:"workdir" json:"workdir"`
	// contains filtered or unexported fields
}

Probe defines a checker for a Step's health

type Spinner

type Spinner struct {
	UUID string
	Name string
	// contains filtered or unexported fields
}

Spinner is the main component that runs a process

func NewSpinnerForPreflight

func NewSpinnerForPreflight(ctx context.Context, preflight *Preflight) (*Spinner, error)

NewSpinnerForPreflight creates a new instance of Spinner based on the Options

func NewSpinnerForProbe

func NewSpinnerForProbe(ctx context.Context, step Step) (*Spinner, error)

NewSpinnerForProbe creates a new instance of Spinner based on the Options

func NewSpinnerForStep

func NewSpinnerForStep(ctx context.Context, step Step) (*Spinner, error)

NewSpinnerForStep creates a new instance of Spinner based on the Options

func (*Spinner) Run

func (s *Spinner) Run(ctx context.Context) error

Run runs the process required

type Step

type Step struct {
	Metadata       map[string]string `yaml:"metadata" json:"metadata"`
	Name           string            `yaml:"name" json:"name"`
	Command        string            `yaml:"command" json:"command"`
	ContinueOnFail bool              `yaml:"continue_on_fail" json:"continue_on_fail"`
	Timeout        *time.Duration    `yaml:"timeout" json:"timeout"`
	Workdir        string            `yaml:"workdir" json:"workdir"`
	Env            []string          `yaml:"env" json:"env"`
	Probe          *Probe            `yaml:"probe" json:"probe"`
	DependsOn      []string          `yaml:"depends_on" json:"depends_on"`
	Preflights     []Preflight       `yaml:"preflights" json:"preflights"`
	AskToProceed   bool              `yaml:"ask_to_proceed" json:"ask_to_proceed"`
	ShowCommand    bool              `yaml:"show_command" json:"show_command"`
	Disabled       bool              `yaml:"disabled" json:"disabled"`
	Logger         *LogDefinition    `yaml:"logger" json:"logger"`
	SessionID      string
	// contains filtered or unexported fields
}

Step is a single running Step

func (*Step) EnrichStep

func (s *Step) EnrichStep(ctx context.Context) error

EnrichStep resolves environment variables and parses the command for the step on all applicable attributes

func (*Step) GetMetaData

func (s *Step) GetMetaData(key string) string

GetMetaData returns metadata value of the key from this Step. this is useful in event notifiers. It will return "" if there is no metadata with the given key

func (*Step) MarkAsPending

func (s *Step) MarkAsPending()

MarkAsPending marks the step as pending meaning it's waiting to run

func (*Step) MergedMetadata

func (s *Step) MergedMetadata() map[string]string

MergedMetadata merges step and workflow metadata

func (*Step) Run

func (s *Step) Run(ctx context.Context) error

Run runs a Step and its probe

func (*Step) String

func (s *Step) String() string

String overrides string

type StepOptions

type StepOptions struct {
	Notifier func(ctx context.Context, logger *logrus.Logger, event *Event) error
}

StepOptions provides options for a Step

type Workflow

type Workflow struct {
	Version  string            `yaml:"version" json:"version"`
	Metadata map[string]string `yaml:"metadata" json:"metadata"`
	Steps    []*Step           `yaml:"steps" json:"steps"`
	Logger   *LogDefinition    `yaml:"logger" json:"logger"`
	// contains filtered or unexported fields
}

Workflow is the internal object to hold a workflow file

func LoadWorkflowFromBytes

func LoadWorkflowFromBytes(ctx context.Context, options *WorkflowOptions, buff []byte) (*Workflow, error)

LoadWorkflowFromBytes loads a workflow from bytes

func LoadWorkflowFromReader

func LoadWorkflowFromReader(ctx context.Context, options *WorkflowOptions, reader io.Reader) (*Workflow, error)

LoadWorkflowFromReader loads a workflow from an io reader

func (*Workflow) EnrichWorkflow

func (w *Workflow) EnrichWorkflow(ctx context.Context) error

EnrichWorkflow parses and replaces any placeholders in the workflow

func (*Workflow) Run

func (w *Workflow) Run(ctx context.Context) (runErrors error, stepErrors error)

Run runs the entire workflow

func (*Workflow) SessionID

func (w *Workflow) SessionID() string

SessionID returns the session id of this run for the workflow

type WorkflowOptions

type WorkflowOptions struct {
	Notifier    func(ctx context.Context, logger *logrus.Logger, event *Event) error
	Concurrency int
	Timeout     time.Duration
	Metadata    map[string]string
}

WorkflowOptions provides options for a workflow

Jump to

Keyboard shortcuts

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