增加定时同步组织架构
This commit is contained in:
15
lifespan.py
15
lifespan.py
@@ -4,6 +4,20 @@ from fastapi import FastAPI
|
||||
from uvicorn.server import logger
|
||||
|
||||
|
||||
async def test_init():
|
||||
from service.sync.department import sync_department, check_department_datebase
|
||||
from service.sync.employee import sync_department_user, check_employee_datebase
|
||||
|
||||
if not check_department_datebase():
|
||||
logger.info("[数据库] 开始同步部门 📦")
|
||||
await sync_department()
|
||||
logger.info("[数据库] 同步部门完成 📦")
|
||||
if not check_employee_datebase():
|
||||
logger.info("[数据库] 开始同步员工 📦")
|
||||
await sync_department_user()
|
||||
logger.info("[数据库] 同步员工完成 📦")
|
||||
|
||||
|
||||
def init_database():
|
||||
from model import create_db_and_tables
|
||||
|
||||
@@ -49,5 +63,6 @@ async def lifespan(app: FastAPI):
|
||||
import_router(app)
|
||||
init_scheduler(app)
|
||||
await import_mcp_server(app)
|
||||
await test_init()
|
||||
yield
|
||||
logger.info(f"[生命周期] 应用关闭 🔧✅")
|
||||
|
||||
Reference in New Issue
Block a user