Releases: go-coldbrew/workers
Releases · go-coldbrew/workers
v0.2.1
v0.2.0
What's Changed
Zombie child auto-cleanup
Stopped children are automatically pruned from GetChildren/GetChild/GetChildCount via a done channel closed on permanent stop. No manual cleanup needed.
ErrSkipTick
New sentinel for periodic handlers to skip a tick without triggering restart — useful for transient failures (DB timeouts, network blips). The timer continues and the next tick fires normally.
Always-sampled worker traces
middleware.Tracing() now ensures worker root spans are always sampled, fixing silent span drops with ParentBased(TraceIDRatioBased(...)) samplers. OTEL trace ID is injected into the log context as trace for correlation.
New APIs
WorkerInfo.GetHandler()— access the current worker'sCycleHandlerfor type assertion (handler-as-metadata pattern)WorkerInfo.GetChildCount()— efficient child count without allocating a sorted sliceWorker.GetInterval(),Worker.GetRestartOnFail(),Worker.GetJitterPercent(),Worker.GetInitialDelay()— config introspection for reconciler patternsmiddleware.WithSkipOnNotAcquired()— convenienceLockOptionfor log-and-skip when distributed lock is held
Documentation
- Error semantics decision table for periodic handlers
- Run-level vs worker-level interceptor guidance
- Handler-as-metadata reconciler example (
Example_reconcilerWithChangeDetection) WithOnNotAcquiredfootgun warningLockerinterface compatibility note
v0.1.0
Workers v0.1.0 — Jitter, Middleware, and API Redesign
Breaking changes (from v0.0.x)
NewWorker(name, fn)→NewWorker(name).HandlerFunc(fn)WorkerContext→*WorkerInfowithGetName(),GetAttempt()gettersctx.Add/Remove/Children→info.Add/Remove/GetChildrenAddis now a no-op if name exists (returns bool) — useRemove+Addto replace- Restart enabled by default —
WithRestart(false)to disable ChannelWorker/BatchChannelWorkercallback signatures updated
New features
- Composable middleware — gRPC-style interceptor chain with
Interceptors()/AddInterceptors()/WithInterceptors() - Built-in middleware (
middleware/sub-package): Recover, Tracing, Duration, Timeout, Slog, LogContext, DistributedLock, DefaultInterceptors - Jitter —
WithJitter(percent),WithDefaultJitter(percent),WithInitialDelay(d)to prevent thundering herd - ErrDoNotRestart — explicit permanent completion signal
- CycleHandler interface with
Close()— resource cleanup on permanent stop - Worker.GetChild() — inspect running children (returns value copy)
- WithTestChildren(ctx) — testable WorkerInfo without running full supervisor
- Slim
Serve()— tracing/logging moved to middleware; core dropsgo-coldbrew/logandgo-coldbrew/tracingimports WithBackoffJitteracceptsfunc(time.Duration) time.Duration— no suture dependency leak