Skip to content

Releases: 0xsequence/runnable

v0.1.0 — adapters subpackage with chi-style middleware + Publisher events

13 May 14:12
a83d8cb

Choose a tag to compare

First post-v0.0.x release. Reshapes cross-cutting behavior into a chi-style middleware subpackage and introduces a typed event Publisher so observers can subscribe to adapter events without coupling to the core.

Highlights

  • New runnable/adapters subpackage providing chi-style middleware constructors that return runnable.Adapter (= func(next RunFunc) RunFunc):
    • adapters.Draining(timeout) — graceful shutdown. Outer ctx cancellation triggers drain: work has timeout to return via adapters.Stopping(ctx) before its ctx is force-cancelled and adapters.ErrDrainTimedOut is returned.
    • adapters.Ticker(interval) — periodic execution. Composes with Draining: an in-flight tick is allowed to finish before exit.
    • adapters.Recovering() — converts panics into errors and publishes a runnable.PanicRecoveredEvent.
    • adapters.Retry(maxRetries, resetAfter) — re-invokes on non-context errors; publishes a runnable.RetryEvent per failed attempt.
  • New core types and Options:
    • runnable.RunFunc and runnable.Adapter as the extension point.
    • runnable.WithAdapters(...Adapter) — applies adapters left-to-right (first listed = outermost).
  • New observability layer (runnable.Publisher interface):
    • runnable.WithPublisher(p) installs a Publisher on the runnable's ctx. Multiple calls fan out via runnable.Publishers.
    • Adapters publish typed events: RetryEvent, DrainStartedEvent, DrainTimedOutEvent, PanicRecoveredEvent.
    • StatusStore is a Publisher and counts RetryEvents into Status.Restarts (replacing the old WithRetry onStart side-channel).
  • NewGroup correctly propagates drain to Draining-wrapped children — was silently broken when drain was being prototyped on a branch; now correct by construction.

Final shape

r := runnable.New(reconcile, runnable.WithAdapters(
    adapters.Draining(10*time.Second),
    adapters.Recovering(),
    adapters.Retry(3, time.Minute),
    adapters.Ticker(2*time.Second),
))

Breaking changes from v0.0.3

  • runnable.WithRetry, runnable.ResetNeveradapters.Retry, adapters.ResetNever.
  • runnable.WithRecovereradapters.Recovering() plus a runnable.WithPublisher subscriber listening for runnable.PanicRecoveredEvent. The two-interface RecoveryReporter / StackPrinter split is gone in favor of a single Publisher.

Status.Restarts is unchanged from the caller's perspective but is now incremented from RetryEvent rather than an internal onStart callback. No call-site change required when using WithStatus + adapters.Retry.

CI

CI now reads the Go version from go.mod (was pinned to 1.20). actions/checkout@v4 + actions/setup-go@v5.

Compatibility

Go 1.21+ (uses context.WithoutCancel).

Full diff: v0.0.3...v0.1.0

v0.0.3

28 Nov 13:33
3743221

Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v0.0.2...v0.0.3