Spaces:
Runtime error
Runtime error
| import asyncio | |
| import sys | |
| import os | |
| # 将项目根目录加入 sys.path,以便直接运行该脚本 | |
| sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) | |
| from packages.core.logger import app_logger | |
| from packages.core.database import engine, Base, AsyncSessionLocal | |
| from packages.connectors.mock.us_mock import MockUSConnector | |
| async def init_db(): | |
| """初始化数据库表结构""" | |
| app_logger.info("Initializing database tables...") | |
| async with engine.begin() as conn: | |
| await conn.run_sync(Base.metadata.create_all) | |
| app_logger.info("Database tables initialized.") | |
| async def run_mock_job(): | |
| """运行 Mock Connector 验证链路""" | |
| app_logger.info("Starting mock job...") | |
| async with AsyncSessionLocal() as session: | |
| connector = MockUSConnector(session) | |
| await connector.run() | |
| async def main(): | |
| try: | |
| await init_db() | |
| await run_mock_job() | |
| except Exception as e: | |
| app_logger.error(f"Execution failed: {e}") | |
| if __name__ == "__main__": | |
| asyncio.run(main()) | |