dheraingoud's picture
sync: upstream 9194f15 + custom addons (KeyRotator, RotatingChatTransport, sol/terra/luna, ScannerTrap, health, Py3.12 compat)
e99df76
Raw History Blame Contribute Delete
1.11 kB
from __future__ import annotations
"""Shared cleanup reporting for runtime resource owners."""
from collections.abc import Awaitable
from loguru import logger
async def best_effort(
name: str,
awaitable: Awaitable[object],
*,
log_verbose_errors: bool = False,
) -> bool:
"""Run one cleanup step and report whether it completed.
The lifecycle owner intentionally applies no generic timeout here. Cancelling
an arbitrary cleanup at a deadline can abandon a half-closed SDK, thread, or
provider resource; resource-specific cleanup or the process supervisor owns
any force-termination deadline.
"""
try:
await awaitable
except Exception as exc:
if log_verbose_errors:
logger.warning(
"Shutdown step failed: {}: {}: {}",
name,
type(exc).__name__,
exc,
)
else:
logger.warning(
"Shutdown step failed: {}: exc_type={}",
name,
type(exc).__name__,
)
return False
return True