LitServe
LitServe copied to clipboard
Feat: Add support for fastapi lifespan events
🚀 Feature
Add the ability for developers to customize the FastAPI lifespan
, startup
, and 'shutdown` event handlers.
Motivation
Users can use this to setup logging or resource management.
Pitch
There are 2 options here.
-
Add a function
attach_event_handler(event: str, func: Callable)
which takes either 'lifespan', 'startup' or 'shutdown' as the event and applies the given logic. -
More explicit and abstracting away FastAPI Lifespan event knowledge from the user, add
during_lifespan(func: Callable)
,on_startup(func: Callable)
, andon_shutdown(func: Callable)
that the user can call on Server to apply these lifespan handlers.
Alternatives
Add custom template startup and shutdown event handler for logging and resource management. This will get cumbersome.