Add an event handler function for startup or shutdown. This method is kept for backward compatibility after Starlette removed support for on_startup/on_shutdown handlers. Ref: https://github.com/Kludex/starlette/pull/3117
(
self,
event_type: str,
func: Callable[[], Any],
)
| 6343 | |
| 6344 | # TODO: remove this once the lifespan (or alternative) interface is improved |
| 6345 | def add_event_handler( |
| 6346 | self, |
| 6347 | event_type: str, |
| 6348 | func: Callable[[], Any], |
| 6349 | ) -> None: |
| 6350 | """ |
| 6351 | Add an event handler function for startup or shutdown. |
| 6352 | |
| 6353 | This method is kept for backward compatibility after Starlette removed |
| 6354 | support for on_startup/on_shutdown handlers. |
| 6355 | |
| 6356 | Ref: https://github.com/Kludex/starlette/pull/3117 |
| 6357 | """ |
| 6358 | assert event_type in ("startup", "shutdown") |
| 6359 | if event_type == "startup": |
| 6360 | self.on_startup.append(func) |
| 6361 | else: |
| 6362 | self.on_shutdown.append(func) |
| 6363 | |
| 6364 | @deprecated( |
| 6365 | """ |
no outgoing calls
no test coverage detected