Documentation
¶
Overview ¶
Package worker implements anchor's consumer: the loop that claims runs from the queue, re-executes them under replay to their frontier, and persists exactly one outcome per claim. The worker is a loop, not a service — it exposes no listener and accepts no inbound calls. Every arrow points outward: to the ledger for truth, to the queue for flow. That is what lets any number of workers run anywhere without coordination beyond the two interfaces.
Index ¶
- type Option
- func WithBackoff(fn func(attempt int) time.Duration) Option
- func WithCodec(c run.Codec) Option
- func WithConcurrency(n int) Option
- func WithHeartbeatEvery(d time.Duration) Option
- func WithJanitorEvery(d time.Duration) Option
- func WithLeaseTTL(d time.Duration) Option
- func WithLogger(l *slog.Logger) Option
- func WithRegistry(r *run.Registry) Option
- type Worker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*options)
Option configures a Worker.
func WithBackoff ¶
WithBackoff sets the retry delay as a function of the failure count just reached. The default is exponential — 250ms·2^(n−1) capped at 30s — with ±20% jitter so a synchronized fleet spreads its retries.
func WithCodec ¶
WithCodec overrides the default JSON codec. It must match the codec the submitting client used.
func WithConcurrency ¶
WithConcurrency sets the number of claim slots (default GOMAXPROCS).
func WithHeartbeatEvery ¶
WithHeartbeatEvery sets the lease renewal interval (default LeaseTTL/3).
func WithJanitorEvery ¶
WithJanitorEvery sets the repair-loop interval (default 30s); 0 disables the janitor on this worker.
func WithLeaseTTL ¶
WithLeaseTTL sets the claim lease duration (default 30s). Heartbeats renew it; a worker that stops heartbeating loses the run after at most this long.
func WithLogger ¶
WithLogger sets the logger for warnings (default slog.Default()).
func WithRegistry ¶
WithRegistry sets the registry workflow names are resolved against (default run.DefaultRegistry).
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker consumes runs. Each claim is driven through a fixed protocol — claim → load → replay to frontier → exactly one of Complete+Settle, Settle (park), or Release (retry) — with lease expiry covering the paths where the worker itself dies. Create with New, start with Run.
func New ¶
New composes a worker over any Ledger and Queue implementation. The queue's DeltaLog capability is discovered by type assertion; without it, attempt dividers are skipped and streams are simply not produced.