mirror of
https://github.com/cnlimiter/codex-register.git
synced 2026-05-06 20:02:51 +08:00
fix(db): prevent SQLite lock issues by increasing timeout and improving task sync
This commit is contained in:
@@ -45,7 +45,7 @@ class DatabaseSessionManager:
|
||||
self.database_url = _build_sqlalchemy_url(database_url)
|
||||
self.engine = create_engine(
|
||||
self.database_url,
|
||||
connect_args={"check_same_thread": False} if self.database_url.startswith("sqlite") else {},
|
||||
connect_args={"check_same_thread": False, "timeout": 30} if self.database_url.startswith("sqlite") else {},
|
||||
echo=False, # 设置为 True 可以查看所有 SQL 语句
|
||||
pool_pre_ping=True # 连接池预检查
|
||||
)
|
||||
|
||||
@@ -33,6 +33,11 @@ if getattr(sys, 'frozen', False):
|
||||
else:
|
||||
_RESOURCE_ROOT = Path(__file__).parent.parent.parent
|
||||
|
||||
if __name__ == "__main__":
|
||||
from webui import setup_application as _setup_application
|
||||
|
||||
_setup_application()
|
||||
|
||||
# 静态文件和模板目录
|
||||
STATIC_DIR = _RESOURCE_ROOT / "static"
|
||||
TEMPLATES_DIR = _RESOURCE_ROOT / "templates"
|
||||
@@ -219,3 +224,23 @@ def create_app() -> FastAPI:
|
||||
|
||||
# 创建全局应用实例
|
||||
app = create_app()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
settings = get_settings()
|
||||
logger.info(
|
||||
"通过模块入口启动 Web UI: http://%s:%s",
|
||||
settings.webui_host,
|
||||
settings.webui_port,
|
||||
)
|
||||
uvicorn.run(
|
||||
app,
|
||||
host=settings.webui_host,
|
||||
port=settings.webui_port,
|
||||
reload=False,
|
||||
log_level="info" if settings.debug else "warning",
|
||||
access_log=settings.debug,
|
||||
ws="websockets",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user