Skip to content
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

Cleanup storage integration and write pending batches on shutdown #76

Merged
merged 3 commits into from
Jan 16, 2024

Conversation

ehclark
Copy link
Contributor

@ehclark ehclark commented Jan 11, 2024

The integration used by AnyVar to store, retrieve and query VRS objects should be provided an opportunity to complete pending work, shutdown and clean up when an AnyVar worker is shutdown. The FastAPI provides lifespan events that can be used for this purpose.

The changes simply make the close() method part of the _Storage API definition and then call the method when the shutdown occurs. Implementations of the close() already existed for both the PostgreSQL and Snowflake storage implementations.

The existing startup event handler was moved to a new lifespan method and the call to close() added to the lifespan method. Event handlers have been deprecated in favor of lifespan.

See also #66

…ents in FastAPI

Add storage.close() to the shutdown phase of the lifespan method
Use fully-qualified names for create_storage() and create_translator() methods so they can be mocked for unit tests
@ehclark ehclark linked an issue Jan 11, 2024 that may be closed by this pull request
Copy link
Contributor

@jsstevenson jsstevenson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 this is great, I didn't realize they'd deprecated the startup event

Copy link
Member

@ahwagner ahwagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. TIL about FastAPI lifespans! Thanks for this addition @ehclark.

@ehclark ehclark merged commit 4a93706 into main Jan 16, 2024
5 checks passed
@ehclark ehclark deleted the issue-66 branch January 16, 2024 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a shutdown API to enable graceful termination of AnyVar
4 participants