Skip to content

Commit

Permalink
Add logging for service cleanup hooks in new-style BentoML services (#…
Browse files Browse the repository at this point in the history
…5171)

* Add logging for new-style service shutdown hooks in app.py

Co-Authored-By: frost@bentoml.com <frost@bentoml.com>

* refactor: improve service cleanup hook logging

Co-Authored-By: frost@bentoml.com <frost@bentoml.com>

* feat: add service instance cleanup completion logging

Co-Authored-By: frost@bentoml.com <frost@bentoml.com>

* refactor: move final cleanup log after proxy closure

Co-Authored-By: frost@bentoml.com <frost@bentoml.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: frost@bentoml.com <frost@bentoml.com>
  • Loading branch information
devin-ai-integration[bot] and frost@bentoml.com authored Jan 7, 2025
1 parent 425239d commit d1a43c7
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/_bentoml_impl/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,21 @@ async def destroy_instance(self, _: Starlette) -> None:
# Call on_shutdown hook with optional ctx or context parameter
for name, member in vars(self.service.inner).items():
if callable(member) and getattr(member, "__bentoml_shutdown_hook__", False):
logger.info("Running cleanup hook: %s", name)
result = getattr(
self._service_instance, name
)() # call the bound method
if inspect.isawaitable(result):
await result
logger.info("Completed async cleanup hook: %s", name)
else:
logger.info("Completed cleanup hook: %s", name)

await cleanup()
own_proxy = getattr(self._service_instance, "__self_proxy__", None)
if isinstance(own_proxy, RemoteProxy):
await own_proxy.close()
logger.info("Service instance cleanup finalized")
self._service_instance = None
set_current_service(None)
await self._result_store.__aexit__(None, None, None)
Expand Down

0 comments on commit d1a43c7

Please sign in to comment.