Add ConsumerSupervisor for background task management#18
Merged
Conversation
…loop Phase 4: Keycloak realm/user/client creation - Add platform client creation to OIDCHandler with create_client() - Add token mapper method to include org claim in JWT tokens - Store platform_client_id in runtime state for later use - This unblocks Phase 6 (in-world realms) and OIDC-authenticated API calls Phase 5: pgmq consumer loop supervision - Create ConsumerSupervisor to manage long-running consumer tasks - Add automatic restart on consumer failure with exponential backoff - Integrate supervisor into orchestrator and pass to phase context - Register DNS update consumer with supervisor in Phase 5 - Update CLI to start consumers after phases complete and keep event loop alive - Add error handling and logging to DNS consumer loop for visibility - Consumer loops now properly process queued DNS update events This ensures: - Keycloak platform realm is fully bootstrapped with client credentials - DNS updates from domain registrations are actually consumed and processed - Background consumers stay alive and restart on failure - Event loop remains active to support async event processing Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017q7TcBiinkpr66zwYFgjHB
- Add proper type annotations to ConsumerSupervisor for mypy strict mode - Fix CLI to only keep event loop alive if consumers are registered - Update test mocking to handle async operations and empty consumer list - Format code with Black for linting compliance - Prevent test timeout by exiting when no consumers are registered Resolves PR #18 CI failures (linting, type checking, test failures). Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017q7TcBiinkpr66zwYFgjHB
- Add type hints to BaseNetEngineException.__init__ parameters (*args, **kwargs) - Add Any type annotations to dict type arguments - Fix kwargs unpacking: for k, v in kwargs.items() - Add missing return type annotation -> None - Add __future__ import for type hints - Format with Black Fixes mypy --strict errors and linting issues in errors.py. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017q7TcBiinkpr66zwYFgjHB
The get_logger import was not being used, causing flake8 F401 error. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017q7TcBiinkpr66zwYFgjHB
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.
Summary
This PR introduces a
ConsumerSupervisorclass to manage long-running consumer tasks (like DNS update processing) with automatic restart on failure. It refactors the DNS consumer from an ad-hoc background task into a supervised, managed consumer that runs after all phases complete.Key Changes
New
ConsumerSupervisorclass (netengine/core/consumer_supervisor.py):Orchestrator integration (
netengine/core/orchestrator.py):ConsumerSupervisorin orchestrator constructorPhaseContextfor access by phase handlersstart_consumers()method to start all registered consumers after phases completePhase context updates (
netengine/handlers/context.py):consumer_supervisorfield toPhaseContextwith TYPE_CHECKING import to avoid circular dependenciesDNS consumer refactoring (
netengine/phases/phase_registries.py):asyncio.create_task()with supervisor registrationOIDC handler enhancement (
netengine/handlers/oidc_handler.py):add_token_mapper()method to configure protocol mappers for JWT claimsPlatform identity phase updates (
netengine/phases/phase_platform_identity.py):CLI updates (
netengine/cli/main.py):Implementation Details
The
ConsumerSupervisorwraps consumer coroutines in a supervised loop that automatically restarts them on failure. This provides resilience for long-running background tasks without requiring manual restart logic. The DNS consumer now properly handles message processing errors by archiving failed messages to a DLQ, improving observability and error recovery.https://claude.ai/code/session_017q7TcBiinkpr66zwYFgjHB