|
|
|
@ -1,23 +1,16 @@
|
|
|
|
|
import logging
|
|
|
|
|
import threading
|
|
|
|
|
import time
|
|
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
|
from logging.handlers import RotatingFileHandler
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
import asyncio
|
|
|
|
|
import uvicorn
|
|
|
|
|
from fastapi import FastAPI, UploadFile, File, HTTPException
|
|
|
|
|
# 在文件开头添加导入
|
|
|
|
|
from pymysql.cursors import DictCursor
|
|
|
|
|
|
|
|
|
|
from Dao.KbDao import KbDao
|
|
|
|
|
from Model.KbModel import KbModel, KbFileModel
|
|
|
|
|
from Test.T9_TestReadPptx import extract_text_from_pptx
|
|
|
|
|
from Util import PdfUtil, WordUtil
|
|
|
|
|
from Util.MySQLUtil import init_mysql_pool
|
|
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
from logging.handlers import RotatingFileHandler
|
|
|
|
|
|
|
|
|
|
# 确保logger已在文件开头正确初始化
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
logger.setLevel(logging.INFO)
|
|
|
|
|
handler = RotatingFileHandler('Logs/document_processor.log', maxBytes=1024*1024, backupCount=5)
|
|
|
|
@ -30,7 +23,6 @@ async def lifespan(app: FastAPI):
|
|
|
|
|
app.state.kb_dao = KbDao(await init_mysql_pool())
|
|
|
|
|
|
|
|
|
|
# 启动文档处理线程
|
|
|
|
|
# 修改函数定义
|
|
|
|
|
async def document_processor():
|
|
|
|
|
while True:
|
|
|
|
|
try:
|
|
|
|
@ -44,10 +36,7 @@ async def lifespan(app: FastAPI):
|
|
|
|
|
|
|
|
|
|
time.sleep(10) # 每10秒检查一次
|
|
|
|
|
|
|
|
|
|
# 修改线程启动部分
|
|
|
|
|
# 修改线程启动方式
|
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run_async_in_thread():
|
|
|
|
|
loop = asyncio.new_event_loop()
|
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
@ -246,12 +235,4 @@ async def upload_file(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 确保logger已在文件开头正确初始化
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
logger.setLevel(logging.INFO)
|
|
|
|
|
handler = RotatingFileHandler('Logs/document_processor.log', maxBytes=1024*1024, backupCount=5)
|
|
|
|
|
handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
|
|
|
|
|
logger.addHandler(handler)
|
|
|
|
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|