go-coldbrew/workers is a worker lifecycle library built on thejerf/suture. It manages background goroutines with panic recovery, configurable restart, tracing, and structured shutdown.
make build # go build ./...
make test # go test -race ./...
make lint # golangci-lint + govulncheck
make bench # benchmarks
make doc # regenerate README.md via gomarkdocEvery worker runs inside its own suture supervisor subtree:
Root Supervisor (created by Run)
├── Worker-A supervisor
│ ├── Worker-A run func
│ ├── Child-A1 supervisor (added via ctx.Add)
│ │ └── Child-A1 run func
│ └── Child-A2 supervisor
│ └── Child-A2 run func
└── Worker-B supervisor
└── Worker-B run func
Key properties:
- Scoped lifecycle: when a parent stops, all children stop
- Independent restart: each worker restarts independently via suture
- Panic recovery: suture catches panics and converts to errors
- Backoff: configurable exponential backoff with jitter on restart
- Tracing: each worker execution gets an OTEL span via
go-coldbrew/tracing
Worker— struct with builder pattern (NewWorker().WithRestart().Every())WorkerContext— extendscontext.ContextwithName(),Attempt(),Add(),Remove(),Children()Run(ctx, []*Worker) error— starts all workers, blocks until ctx cancelledRunWorker(ctx, *Worker)— runs a single worker
EveryInterval(d, fn)— periodic ticker loopChannelWorker[T](ch, fn)— consume from channelBatchChannelWorker[T](ch, maxSize, maxDelay, fn)— batch with size/timer flush
- Always run
make docafter changing exported APIs or docstrings - Always run
make testandmake lintbefore committing - Don't add
replacedirectives to go.mod