Repository navigation
feat: add App and Readiness for ordered start, staged stop and drain - #2
Merged
Merged
Conversation
Module github.com/dioad/lifecycle with the same verify gate as dioad/net (fmt, fix, golangci-lint, gosec, vet, test -race, build). The Makefile sets GOWORK=off so the module is verified against the versions its go.mod declares. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SS4MAv4S7Lw7pGWvpgXpcr
App starts services in registration order and rolls back the ones that had started when a service fails; stops them in stages, each with an optional budget, concurrently within a stage, all inside one stop timeout; fans the failures of services that implement Failer into one channel; and drains before it stops, unless a failure caused the stop. Readiness is a health source with a start gate, named checks cached for a TTL, a degraded state that keeps the process ready, and a drain. It has the Ready method dioad/net's HTTP server looks for, without importing it. Service uses Shutdown rather than Stop so that dioad/net's http.Server is a Service with no adapter. Failed, Live and Ready are optional. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SS4MAv4S7Lw7pGWvpgXpcr
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SS4MAv4S7Lw7pGWvpgXpcr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the lifecycle package proposed in #1.
What it adds
Apperrors.Join.Failed() <-chan errorinto one channel, as a*ServiceErrornaming the service.Rundrains before it stops when its context is done, and skips the drain when a failure caused the stop.ReadinessReady(ctx) (any, error)method thatdioad/net'sAddHealthSourcelooks for, so/health/readyreports it without this module importing net.ExampleApp,ExampleApp_StopandExampleReadiness, each with a checked// Output:.Makefileverify gate (same as dioad/net, withGOWORK=off),.golangci.yml, and a CI workflow.Deviations from #1
Shutdown, notStop. Shared process lifecycle: ordered start, staged stop, failure fan-in, readiness and drain #1 asks forStop(ctx)and also for*dch.Serverto be aServicewith no adapter;dioad/net'shttp.ServerhasShutdown, so the name follows the second goal.Failed,LiveandReadyare optional, found by interface assertion.New(mgmt OperationalConfig, primary *dch.Server, ...)constructor. It would make this module importdioad/netwhile net's examples import this module, creating a module cycle. A convenience constructor can live in net.Not in this PR
Migrating the
dioad/netexamples onto this package (the worker-daemon example,api-server, and the compile-timelifecycle.Servicecheck for*http.Server) needs a tagged release and ago.modbump in net, so it is a follow-up there. #1 stays open for it.Verification
make verifypasses (fmt, fix, golangci-lint, gosec, vet,go test -race, build). The tests also pass 30 times in a row under-race. They cover start order and rollback, staged and concurrent stop, stage budgets and the overall deadline, failure fan-in (including that watchers do not leak after a clean stop), drain skipped on failure, and the readiness gate, degraded checks and TTL caching.🤖 Generated with Claude Code