Repository navigation
Stop the hosted application's engine while HTTP is idle - #259
Merged
Merged
Conversation
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.
Keep
main.gofocused on running the bank's Dogma application and serving its web UI. It constructs the application, engine, and UI handler normally, then adds the public demo's idle shutdown through one optionalidletimeout.Inject()call. There is one errgroup and one HTTP server.When
DOGMA_EXAMPLE_IDLE_TIMEOUTis set to a positive duration such as1m,Inject()replaces the engine runner, UI command executor, and outer HTTP handler before they start. The lifetime manager uses the already-created engine first, then calls the sharednewEngine()factory after subsequent idle shutdowns. Commands and their options are forwarded to the current engine. Concurrent visitors share one engine, and a replacement waits for the previous engine to stop.The projection and engine database pools remain fixed for the process lifetime.
Inject()configures their unused connections to expire naturally. With the variable unset, the UI submits commands directly to the engine and the engine runs continuously.The HTTP server, request deadlines, connection timeouts, logging, signal handling, and graceful shutdown remain visible in
main.go.DOGMA_EXAMPLE_LISTEN_ADDRESSdefaults to:8080. The Dockerfile and command are unchanged.The public demo uses a JSON logger on stdout so its log collector can parse levels and attributes. Local runs use text logs on stdout.
main()selects the format from the existingDOGMA_EXAMPLE_IDLE_TIMEOUTsetting before creating the one shared logger for the engine, HTTP server, and idle manager.run()owns signal handling and all deferred cleanup. It treats cancellation as a successful shutdown on every return path, including during startup.main()creates the logger and reports failures afterrun()returns; it has no deferred cleanup.HTTP health checks and other probes count as activity. Scheduled work waits until the engine wakes. Platform sleeping must be enabled separately.
Validation:
go test ./...,go test -race ./internal/idletimeout,go vet ./..., andgo fix -diff ./...passed.1ac8274separately verified the platform's actual sleep/wake behavior and a fresh process after waking.