dispatch

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package dispatch owns the run lifecycle: routing repos to executors and serializing runs per repo with debounce, coalescing and timeouts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dispatcher

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

Dispatcher owns the per-repo run lifecycle: debounce, mutual exclusion, rerun coalescing, global concurrency and the run timeout.

func NewDispatcher

func NewDispatcher(st store.Store, router *Router, opts Options) *Dispatcher

NewDispatcher wires a Dispatcher; opts.Log and opts.Metrics may be nil.

func (*Dispatcher) Adopt

func (d *Dispatcher) Adopt(run executor.AdoptedRun, executorName string)

Adopt registers an in-flight run discovered at startup. The repo is locked until wait returns; a deferred rerun fires afterwards if events arrived meanwhile.

func (*Dispatcher) Enqueue

func (d *Dispatcher) Enqueue(ev platform.Event)

Enqueue requests a run for the event's repo. Duplicate requests coalesce: one pending run while queued, one deferred rerun while running.

func (*Dispatcher) SetRouter added in v0.2.0

func (d *Dispatcher) SetRouter(r *Router)

SetRouter atomically swaps the routing rules; subsequent Enqueues use the new rules, in-flight runs are unaffected. Used for SIGHUP reloads.

func (*Dispatcher) Shutdown

func (d *Dispatcher) Shutdown(ctx context.Context) error

Shutdown stops accepting timed work and waits for in-flight runs.

type Metrics

type Metrics interface {
	RunStarted(executorName string)
	RunFinished(executorName, result string, seconds float64)
}

Metrics receives run lifecycle notifications. Implemented by the metrics package; nil-safe via the noop default.

type Options

type Options struct {
	Debounce      time.Duration
	RunTimeout    time.Duration
	MaxConcurrent int
	Log           *slog.Logger
	Metrics       Metrics
	History       Recorder
}

Options configures a Dispatcher.

type Recorder added in v0.2.0

type Recorder interface {
	Record(e history.Entry)
}

Recorder receives an entry for every finished run. Implemented by the history package; nil-safe via the noop default.

type Route

type Route struct {
	Executor executor.Executor // nil iff Disabled
	Disabled bool
}

Route is the outcome of matching a repo against the rules.

type Router

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

Router matches repo full names against ordered rules, first match wins. Config validation guarantees a catch-all rule exists.

func NewRouter

func NewRouter(rules []config.Rule, executors map[string]executor.Executor) (*Router, error)

NewRouter compiles the ordered rules, resolving executor names.

func (*Router) Route

func (r *Router) Route(repoFullName string) Route

Route returns the first matching rule's outcome for a repo full name.

Jump to

Keyboard shortcuts

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