Skip to content

Commit

Permalink
[ENH]: FastAPI Shutdown hook (chroma-core#1665)
Browse files Browse the repository at this point in the history
## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
- On shutdown event system.stop() is called to properly stop all
components

## Test plan
*How are these changes tested?*

- [x] Tests pass locally with `pytest` for python

## Documentation Changes
N/A
  • Loading branch information
tazarov committed Feb 10, 2024
1 parent 54c4369 commit d2b8ac0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions chromadb/server/fastapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ def __init__(self, settings: Settings):
allow_methods=["*"],
)

self._app.on_event("shutdown")(self.shutdown)

if settings.chroma_server_authz_provider:
self._app.add_middleware(
FastAPIChromaAuthzMiddlewareWrapper,
Expand Down Expand Up @@ -280,6 +282,9 @@ def __init__(self, settings: Settings):
use_route_names_as_operation_ids(self._app)
instrument_fastapi(self._app)

def shutdown(self) -> None:
self._system.stop()

def app(self) -> fastapi.FastAPI:
return self._app

Expand Down

0 comments on commit d2b8ac0

Please sign in to comment.