-
Notifications
You must be signed in to change notification settings - Fork 29
🎨 Add Reusable Lifespan Contexts for RabbitMQ and Redis in servicelib.fastapi
#7547
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
🎨 Add Reusable Lifespan Contexts for RabbitMQ and Redis in servicelib.fastapi
#7547
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #7547 +/- ##
==========================================
- Coverage 87.52% 87.40% -0.12%
==========================================
Files 1745 1412 -333
Lines 67554 57856 -9698
Branches 1144 638 -506
==========================================
- Hits 59125 50571 -8554
+ Misses 8108 7089 -1019
+ Partials 321 196 -125
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
b2290e9
to
035f475
Compare
servicelib.fastapi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR extends the lifespan functionality within servicelib.fastapi to support redis, rabbitmq, and postgres by introducing new lifespan contexts and updating associated utilities and tests.
- Added model configuration examples in the settings modules for redis and rabbitmq.
- Introduced new lifespan functions for redis, rabbitmq, and postgres with enhanced error handling and state management.
- Updated lifespan utilities and tests to support stricter lifespan state tracking.
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
packages/settings-library/src/settings_library/redis.py | Added examples via model_config for redis connection settings. |
packages/settings-library/src/settings_library/rabbit.py | Added examples via model_config for rabbitmq connection settings. |
packages/service-library/tests/fastapi/test_redis_lifespan.py | Added tests to verify the redis lifespan behavior and error handling. |
packages/service-library/tests/fastapi/test_rabbitmq_lifespan.py | Added tests for rabbitmq connectivity and RPC client/server lifespans. |
packages/service-library/tests/fastapi/test_lifespan_utils.py | Updated tests for lifespan utility functions and error message changes. |
packages/service-library/src/servicelib/rabbitmq/_client_rpc.py | Introduced rabbitmq_rpc_client_context for managing RPC client context. |
packages/service-library/src/servicelib/rabbitmq/init.py | Exported the new rabbitmq_rpc_client_context for external usage. |
packages/service-library/src/servicelib/fastapi/redis_lifespan.py | Implemented redis lifespan context with proper client shutdown logic. |
packages/service-library/src/servicelib/fastapi/rabbitmq_lifespan.py | Implemented rabbitmq connectivity lifespan with error handling. |
packages/service-library/src/servicelib/fastapi/postgres_lifespan.py | Enhanced postgres lifespan to integrate lifespan_context and called_state. |
packages/service-library/src/servicelib/fastapi/lifespan_utils.py | Updated error message templates and lifespan state management utilities. |
Comments suppressed due to low confidence (1)
packages/service-library/src/servicelib/fastapi/lifespan_utils.py:42
- [nitpick] The function name 'mark_lifespace_called' appears to have a typo. Consider renaming it to 'mark_lifespan_called' for consistency with other lifespan-related function names.
def mark_lifespace_called(state: State, lifespan_name: str) -> State:
servicelib.fastapi
servicelib.fastapi
packages/service-library/src/servicelib/fastapi/postgres_lifespan.py
Outdated
Show resolved
Hide resolved
packages/service-library/src/servicelib/fastapi/lifespan_utils.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool! Thanks a lot. Left a few suggestions
…ogging and state tracking in FastAPI
…FastAPI lifespan management
1559ef7
to
f7f3b24
Compare
|
What do these changes do?
Enhances the
servicelib.fastapi
module by extending its lifespan management functionality using a context manager pattern (on_startup
/on_shutdown
). This update introduces reusable lifespan contexts for managing RabbitMQ (both connection and RPC clients) and Redis resources (only clients).All these new functions are reusable and should drastically reduce the boilerplate to create simcore-service. Please check tests to see usage
Related issue/s
How to test
Dev-ops
None