MCPcopy Create free account
hub / github.com/agentscope-ai/Trinity-RFT / async_run_with_retry_session

Function async_run_with_retry_session

trinity/buffer/utils.py:21–52  ·  view source on GitHub ↗

Run an async database operation with session retry.

(
    session_maker: async_sessionmaker,
    operation: Callable[[AsyncSession], Awaitable[Any]],
    max_retry_times: int = 2,
    max_retry_interval: float = 1.0,
)

Source from the content-addressed store, hash-verified

19
20
21async def async_run_with_retry_session(
22 session_maker: async_sessionmaker,
23 operation: Callable[[AsyncSession], Awaitable[Any]],
24 max_retry_times: int = 2,
25 max_retry_interval: float = 1.0,
26) -> Any:
27 """Run an async database operation with session retry."""
28 logger = get_logger(__name__)
29 max_retry_times = max(1, max_retry_times)
30
31 for attempt in range(max_retry_times):
32 async with session_maker() as session:
33 try:
34 async with session.begin():
35 result = await operation(session)
36 return result
37 except StopAsyncIteration:
38 raise
39 except Exception as exc:
40 logger.warning(
41 "Async attempt %s failed, retrying in %s seconds...",
42 attempt + 1,
43 max_retry_interval,
44 )
45 logger.warning("trace = %s", traceback.format_exc())
46 if attempt < max_retry_times - 1:
47 await asyncio.sleep(max_retry_interval)
48 continue
49 logger.error("Max retry attempts reached, raising exception.")
50 raise exc
51
52 raise RuntimeError("async_run_with_retry_session exhausted without raising")

Callers 9

record_historyMethod · 0.90
update_rewardMethod · 0.90
writeMethod · 0.90
_read_fifoMethod · 0.90
_read_priorityMethod · 0.90
countMethod · 0.90
queryMethod · 0.90
writeMethod · 0.90
readMethod · 0.90

Calls 2

get_loggerFunction · 0.90
sleepMethod · 0.80

Tested by

no test coverage detected