parent
bc517de913
commit
591f5bf770
|
|
@ -8,5 +8,12 @@
|
|||
<jdbc-url>jdbc:mysql://localhost:3306/dict</jdbc-url>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
<data-source source="LOCAL" name="test_db@124.221.145.135" uuid="a23b927c-ada0-4708-ba6e-4db2b9dab6c1">
|
||||
<driver-ref>mysql.8</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mysql://124.221.145.135:3306/test_db</jdbc-url>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -226,7 +226,7 @@ async def update_by_xlsx(
|
|||
await import_wordlist_fr(path=tmp_path)
|
||||
await import_def_fr(path=tmp_path)
|
||||
except Exception as e:
|
||||
# Tortoise ORM 会自动回滚事务,所以无需手动删除已添加内容
|
||||
raise HTTPException(status_code=500, detail=f"导入失败:{str(e)}")
|
||||
#TODO: 导入失败后的回滚(删除本次已经添加的内容)
|
||||
|
||||
return {"message": "导入成功"}
|
||||
|
|
|
|||
3
main.py
3
main.py
|
|
@ -5,6 +5,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
|||
import uvicorn
|
||||
from tortoise.contrib.fastapi import register_tortoise
|
||||
|
||||
from app.utils import redis_client
|
||||
from settings import TORTOISE_ORM
|
||||
from app.api.users import users_router
|
||||
from app.api.admin.router import admin_router
|
||||
|
|
@ -17,7 +18,7 @@ import app.models.signals
|
|||
async def lifespan(app: FastAPI):
|
||||
await init_redis_pool()
|
||||
yield
|
||||
# 可以加 await redis_client.close() 清理资源
|
||||
await redis_client.close() # 清理资源
|
||||
|
||||
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
|
|
|
|||
Loading…
Reference in New Issue