feat: propagate request correlation context

This commit is contained in:
jxxghp
2026-08-21 22:08:33 +08:00
parent c755c074b9
commit 47f1ff9cb4
13 changed files with 408 additions and 41 deletions
+3 -1
View File
@@ -1,6 +1,7 @@
import asyncio
import inspect
import time
from contextvars import copy_context
from functools import partial, wraps
from typing import Any, Callable
@@ -16,7 +17,8 @@ async def run_in_threadpool(
"""在线程中执行同步函数,保持 FastAPI 旧帮助函数的参数语义。"""
if kwargs:
func = partial(func, **kwargs)
return await run_sync(func, *args)
context = copy_context()
return await run_sync(context.run, func, *args)
def retry(ExceptionToCheck: Any,