-
Notifications
You must be signed in to change notification settings - Fork 0
Implement Graceful Shutdown Handler with Configurable Timeout #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
…component classes; add BeanCollection and Component classes with lifecycle management and error handling features.
- Introduced `GracefulShutdownHandler` interface for managing application shutdowns with support for manual, SIGTERM, timeout, and error scenarios. - Updated `PySpringApplication` to initialize graceful shutdown handling during application startup. - Refactored middleware initialization to utilize a common external handler initialization method for better code organization and error handling. - Added unit tests for the `GracefulShutdownHandler` to ensure proper functionality across various shutdown scenarios.
- Updated the initialization of the handler in `PySpringApplication` to specify the type. - Removed the `wait` method from `GracefulShutdownHandler` to streamline shutdown handling. - Deleted the `test_graceful_shutdown.py` file as part of the cleanup process.
- Wrapped shutdown signal handling methods in try-except blocks to catch and handle exceptions gracefully. - Ensured that errors during shutdown processing are reported via the on_error method.
…ceful shutdown initialization
…ndler to streamline the interface and improve code clarity.
- Introduced `ShutdownConfig` class to encapsulate graceful shutdown settings, including timeout and enabled status. - Updated `ApplicationConfig` to include `shutdown_config` for managing shutdown behavior. - Enhanced `GracefulShutdownHandler` to accept timeout parameters and manage shutdown timing. - Modified `PySpringApplication` to utilize the new shutdown configuration during initialization and shutdown processes.
…int statements for SIGINT and SIGTERM signals
… duration for clarity
- Added checks in `_handle_sigint` and `_handle_sigterm` methods to ignore signals if a shutdown is already in progress, improving robustness and logging clarity.
- Introduced comprehensive test suites for `ApplicationConfig` and `ShutdownConfig` to validate default values, custom configurations, serialization, and type validation. - Added tests for graceful shutdown handler functionality, including signal handling, timeout behavior, and error management. - Ensured coverage for various scenarios to enhance reliability and maintainability of the shutdown handling logic.
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.
Implement Graceful Shutdown Handler with Configurable Timeout
🚀 Overview
This PR introduces a comprehensive graceful shutdown handling system for PySpring applications, along with important structural improvements to the codebase. The implementation provides configurable timeout-based shutdown management with proper signal handling and cleanup procedures.
✨ Key Features
🛡️ Graceful Shutdown Handler
SIGINT
(Ctrl+C) andSIGTERM
signals⚙️ Configuration Management
🏗️ Code Structure Improvements
📁 Structural Changes
File Reorganization
New Files
py_spring_core/core/interfaces/graceful_shutdown_handler.py
- Core shutdown handler interfacepy_spring_core/core/utils.py
- Framework utility functionstests/test_application_config.py
- Configuration testingtests/test_graceful_shutdown_handler.py
- Shutdown handler testingtests/test_framework_utils.py
- Utility function testing🔧 Implementation Details
Graceful Shutdown Handler Interface
Configuration Schema
Application Integration
The shutdown handler is automatically:
🧪 Testing
Comprehensive test coverage includes:
🔄 Migration Guide
For Existing Applications
shutdown_config
to application configurationGracefulShutdownHandler
if custom shutdown logic is neededExample Usage
📊 Configuration Example
🛡️ Backward Compatibility
🚦 Testing Instructions
python -m pytest tests/
SIGINT
/SIGTERM
📝 Related Issues
This implementation addresses requirements for: