[fix] cleanup task to other thread
This commit is contained in:
parent
f5d13feaf9
commit
776b513858
3 changed files with 61 additions and 29 deletions
|
|
@ -75,13 +75,25 @@ def _build_shutdown_handler(
|
|||
container: AppContainer,
|
||||
) -> Callable[[], Awaitable[None]]:
|
||||
async def shutdown() -> None:
|
||||
errors: list[Exception] = []
|
||||
|
||||
try:
|
||||
await _stop_cleanup_loop(app)
|
||||
finally:
|
||||
try:
|
||||
_uninstrument_app(app)
|
||||
finally:
|
||||
container.shutdown()
|
||||
except Exception as exc:
|
||||
errors.append(exc)
|
||||
|
||||
try:
|
||||
_uninstrument_app(app)
|
||||
except Exception as exc:
|
||||
errors.append(exc)
|
||||
|
||||
try:
|
||||
container.shutdown()
|
||||
except Exception as exc:
|
||||
errors.append(exc)
|
||||
|
||||
if errors:
|
||||
raise ExceptionGroup('app shutdown failed', errors)
|
||||
|
||||
return shutdown
|
||||
|
||||
|
|
@ -94,7 +106,9 @@ async def _run_cleanup_loop(
|
|||
|
||||
while not stop_event.is_set():
|
||||
try:
|
||||
container.usecases.cleanup_expired_sandboxes.execute()
|
||||
await asyncio.to_thread(
|
||||
container.usecases.cleanup_expired_sandboxes.execute
|
||||
)
|
||||
except Exception as exc:
|
||||
container.observability.logger.error(
|
||||
'sandbox_cleanup_failed',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue