serve

package
v1.44.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package serve keeps running and runs workflows: on a schedule, or again and again, each run a process of probe of its own. It knows nothing of what a run does; it reads what the run reports.

Index

Constants

View Source
const (
	StatusPassed = "passed"
	// StatusFailed is a run whose test or action failed.
	StatusFailed = "failed"
	// StatusError is a run that could not run its workflow, such as one
	// whose workflow cannot run as it is written.
	StatusError   = "error"
	StatusTimeout = "timeout"
	// StatusStopped is a run that serve stopped as it was stopped itself.
	StatusStopped = "stopped"
)

Run statuses, as the serve log tells how a run ended.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Name tells this serve from another in the log.
	Name        string `yaml:"name"`
	Description string `yaml:"description"`
	// Workers is how many runs go at once, across every workflow.
	Workers int     `yaml:"workers"`
	Results Results `yaml:"results"`
	// Grace is how long the runs going when serve is stopped are waited
	// for before they are stopped too.
	Grace     Duration             `yaml:"grace"`
	Workflows map[string]*Workflow `yaml:"workflows"`
	// contains filtered or unexported fields
}

Config is what a serve file says.

func Load

func Load(path string) (*Config, []string, error)

Load reads the serve file at path. The paths it names are taken from the directory it is in. It returns what does not keep it from serving but is likely a mistake, as warnings.

type Duration

type Duration struct {
	time.Duration
	// contains filtered or unexported fields
}

Duration is a duration as a workflow writes one, such as 30s or 1m30s.

func (*Duration) UnmarshalYAML

func (d *Duration) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML reads a duration as duration.Parse does.

type ForEach

type ForEach struct {
	// Items is the output of the run that holds the items, a list of
	// objects, whose keys are the vars of the runs for each.
	Items string `yaml:"items"`
	// Workflow is run for each item.
	Workflow string `yaml:"workflow"`
	// Concurrency is how many items are handled at once.
	Concurrency int `yaml:"concurrency"`
	// OnSuccess is run for an item whose Workflow passed, and OnFailure for
	// one whose Workflow did not; none or empty for nothing.
	OnSuccess string `yaml:"on_success"`
	OnFailure string `yaml:"on_failure"`
}

ForEach is how the items a run gives are handled: each by a run of a workflow, and then by one of another as that run passed or not.

type Results

type Results struct {
	Dir string `yaml:"dir"`
	// Keep is how long a run is kept after it ends; zero keeps every run.
	Keep Duration `yaml:"keep"`
}

Results is where what the runs leave is kept.

type Run

type Run struct {
	Workflow   string
	ID         string
	StartedAt  time.Time
	FinishedAt time.Time
	// ExitStatus is that of the process of the run; -1 when a signal ended
	// it, or it could not be started.
	ExitStatus int
	Status     string
	// Dir is where the run left its report, report.json, and what it
	// wrote, output.log.
	Dir string
	// Err is why the run could not be started, or nil.
	Err error
}

Run is a run of a workflow, as serve tells it once it is over.

func (Run) OutputPath

func (r Run) OutputPath() string

OutputPath returns the path of what the run wrote, its standard output and its standard error.

func (Run) ReportPath

func (r Run) ReportPath() string

ReportPath returns the path of the json report of the run.

type Server

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

Server runs the workflows of a Config.

func New

func New(c *Config, exe string, log *slog.Logger) *Server

New returns a Server of c, whose runs are processes of exe, the probe command, and which logs each run to log, each line with the name of c as serve.

func (*Server) Abort

func (s *Server) Abort()

Abort kills the runs going at once, and any that would start, as a second signal to serve does.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context)

Serve starts the workflows that have a schedule or loop, and runs them until ctx is done. It then starts no run, waits Config.Grace for those going, ends those still going with SIGTERM, and returns once each is over.

func (*Server) Warn

func (s *Server) Warn(warnings ...string)

Warn logs warnings, such as those Load returns, as lines of the log of s.

type Workflow

type Workflow struct {
	Files        []string       `yaml:"files"`
	Vars         map[string]any `yaml:"vars"`
	EnvFiles     []string       `yaml:"env_files"`
	Jobs         []string       `yaml:"jobs"`
	ReadOnly     bool           `yaml:"read_only"`
	AllowHosts   []string       `yaml:"allow_hosts"`
	AllowActions []string       `yaml:"allow_actions"`
	// Schedule is a cron expression of the times the workflow is run at.
	Schedule string `yaml:"schedule"`
	// Loop runs the workflow again once the run before it is over, after
	// Interval.
	Loop     bool     `yaml:"loop"`
	Interval Duration `yaml:"interval"`
	// Timeout ends a run that goes on longer; zero for none.
	Timeout Duration `yaml:"timeout"`
	// ForEach runs another workflow for each item a run of this one gives.
	ForEach *ForEach `yaml:"for_each"`
	// State names outputs of the workflow kept between its runs: saved once
	// a run is over, and given to the next run as vars of the same names.
	State []string `yaml:"state"`
	// contains filtered or unexported fields
}

Workflow is a workflow serve runs, and how a run of it is started.

Jump to

Keyboard shortcuts

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