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

Function init_async_engine

trinity/buffer/schema/sql_schema.py:176–203  ·  view source on GitHub ↗

Create an async SQLAlchemy engine and table classes. Returns: For task schema: (async_engine, table_cls) For experience/sft/dpo schema: (async_engine, meta_cls, blob_cls)

(db_url: str, table_name: str, schema_type: Optional[str])

Source from the content-addressed store, hash-verified

174
175
176async def init_async_engine(db_url: str, table_name: str, schema_type: Optional[str]) -> Tuple:
177 """Create an async SQLAlchemy engine and table classes.
178
179 Returns:
180 For task schema: (async_engine, table_cls)
181 For experience/sft/dpo schema: (async_engine, meta_cls, blob_cls)
182 """
183 from trinity.buffer.utils import to_async_url
184
185 logger = get_logger(__name__)
186 async_url = to_async_url(db_url)
187 engine = create_async_engine(async_url, pool_pre_ping=True)
188
189 if schema_type is None:
190 schema_type = "task"
191
192 classes = _create_table_classes(table_name, schema_type)
193
194 try:
195 async with engine.begin() as conn:
196 await conn.run_sync(Base.metadata.create_all)
197 logger.info(f"Created async tables for {table_name} (schema={schema_type}).")
198 except OperationalError:
199 logger.warning(f"Failed to create async tables for {table_name}, assuming they exist.")
200
201 if schema_type == "task":
202 return engine, classes[0]
203 return engine, classes[0], classes[1]

Callers 3

prepareMethod · 0.90
prepareMethod · 0.90
prepareMethod · 0.90

Calls 3

get_loggerFunction · 0.90
to_async_urlFunction · 0.90
_create_table_classesFunction · 0.85

Tested by

no test coverage detected