Help us shape the future of Go! Take the 2026 Go Developer Survey

watch

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package watch keeps a running zot pointed at a folder - or at a glob naming the orders in one - so work orders are dispatched as they arrive. It is watch mode's engine: the CLI hands it a dispatcher that runs each order exactly as a batch position would, and it sweeps the target forever, so an order dropped into the folder at three in the morning starts without anyone restarting zot.

Sweeping is deliberate polling rather than filesystem events: it is cross-platform by construction, immune to the missed-event races of rename storms, and cheap at the scale a folder of small YAML files lives at.

Index

Constants

View Source
const DefaultInterval = time.Second

DefaultInterval is how often a watched target is swept when WithInterval does not say otherwise.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dispatcher

type Dispatcher interface {
	Dispatch(order.Order)
}

Dispatcher receives every order the watcher picks up. It owns the order's fate - run it, skip it as satisfied, report a failed run - and its errors are its own to report: the watcher keeps watching whatever Dispatch does, because one bad order must not end a factory that is meant to run unattended. The watcher stops only when its context is cancelled.

type Option

type Option func(*Watcher)

Option adjusts a Watcher.

func WithInterval

func WithInterval(d time.Duration) Option

WithInterval sets how often the target is swept.

func WithOutput

func WithOutput(out io.Writer) Option

WithOutput sets where status lines go. Status belongs on stderr - stdout is the transcript of whatever runs - but a test wants to read them, so the default of io.Discard is only right for callers with nothing to hear.

type Watcher

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

Watcher sweeps a target for work orders and dispatches each new one.

func New

func New(target string, d Dispatcher, opts ...Option) (*Watcher, error)

New targets a watch at target - either a plain directory, whose directly contained *.yaml files are all candidates, or a glob pattern such as orders/*.yaml, whose matches are filtered down to *.yaml files. The target is used exactly as given, so a caller resolving against the invoking directory (as the CLI does before its chdir) stays in charge of what it means.

func (*Watcher) Run

func (w *Watcher) Run(ctx context.Context)

Run sweeps until ctx is cancelled: once immediately - so orders already sitting in the target start without waiting an interval - then once per interval. One order runs at a time; Dispatch is called sequentially, so a long run simply delays the next sweep rather than racing it.

Jump to

Keyboard shortcuts

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