Better error handling on backgrounp task thread

This commit is contained in:
MarkRx
2024-05-30 20:22:58 -04:00
parent c9c14c10b0
commit d9a7dae6c4
3 changed files with 15 additions and 6 deletions

View File

@ -43,8 +43,11 @@ def handle_request(
log_context["api_url"] = url log_context["api_url"] = url
async def inner(): async def inner():
try:
with get_logger().contextualize(**log_context): with get_logger().contextualize(**log_context):
await PRAgent().handle_request(url, body) await PRAgent().handle_request(url, body)
except Exception as e:
get_logger().error(f"Failed to handle webhook: {e}")
background_tasks.add_task(inner) background_tasks.add_task(inner)

View File

@ -27,8 +27,11 @@ def handle_request(
log_context["api_url"] = url log_context["api_url"] = url
async def inner(): async def inner():
try:
with get_logger().contextualize(**log_context): with get_logger().contextualize(**log_context):
await PRAgent().handle_request(url, body) await PRAgent().handle_request(url, body)
except Exception as e:
get_logger().error(f"Failed to handle webhook: {e}")
background_tasks.add_task(inner) background_tasks.add_task(inner)

View File

@ -29,8 +29,11 @@ def handle_request(background_tasks: BackgroundTasks, url: str, body: str, log_c
log_context["api_url"] = url log_context["api_url"] = url
async def inner(): async def inner():
try:
with get_logger().contextualize(**log_context): with get_logger().contextualize(**log_context):
await PRAgent().handle_request(url, body) await PRAgent().handle_request(url, body)
except Exception as e:
get_logger().error(f"Failed to handle webhook: {e}")
background_tasks.add_task(inner) background_tasks.add_task(inner)