fix 优化连接参数
This commit is contained in:
parent
453ef94e4d
commit
f15ccadc2d
@ -17,12 +17,11 @@ router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/statistic", summary="媒体数量统计", response_model=schemas.Statistic)
|
||||
def statistic(db: Session = Depends(get_db),
|
||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||
def statistic(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||
"""
|
||||
查询媒体数量统计信息
|
||||
"""
|
||||
media_statistics: Optional[List[schemas.Statistic]] = DashboardChain(db).media_statistic()
|
||||
media_statistics: Optional[List[schemas.Statistic]] = DashboardChain().media_statistic()
|
||||
if media_statistics:
|
||||
# 汇总各媒体库统计信息
|
||||
ret_statistic = schemas.Statistic()
|
||||
@ -57,12 +56,11 @@ def processes(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||
|
||||
|
||||
@router.get("/downloader", summary="下载器信息", response_model=schemas.DownloaderInfo)
|
||||
def downloader(db: Session = Depends(get_db),
|
||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||
def downloader(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||
"""
|
||||
查询下载器信息
|
||||
"""
|
||||
transfer_info = DashboardChain(db).downloader_info()
|
||||
transfer_info = DashboardChain().downloader_info()
|
||||
free_space = SystemUtils.free_space(Path(settings.DOWNLOAD_PATH))
|
||||
if transfer_info:
|
||||
return schemas.DownloaderInfo(
|
||||
|
@ -1,27 +1,25 @@
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, BackgroundTasks, Request, Depends
|
||||
from sqlalchemy.orm import Session
|
||||
from fastapi import APIRouter, BackgroundTasks, Request
|
||||
|
||||
from app import schemas
|
||||
from app.chain.webhook import WebhookChain
|
||||
from app.core.config import settings
|
||||
from app.db import get_db
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
def start_webhook_chain(db: Session, body: Any, form: Any, args: Any):
|
||||
def start_webhook_chain(body: Any, form: Any, args: Any):
|
||||
"""
|
||||
启动链式任务
|
||||
"""
|
||||
WebhookChain(db).message(body=body, form=form, args=args)
|
||||
WebhookChain().message(body=body, form=form, args=args)
|
||||
|
||||
|
||||
@router.post("/", summary="Webhook消息响应", response_model=schemas.Response)
|
||||
async def webhook_message(background_tasks: BackgroundTasks,
|
||||
token: str, request: Request,
|
||||
db: Session = Depends(get_db),) -> Any:
|
||||
) -> Any:
|
||||
"""
|
||||
Webhook响应
|
||||
"""
|
||||
@ -30,19 +28,18 @@ async def webhook_message(background_tasks: BackgroundTasks,
|
||||
body = await request.body()
|
||||
form = await request.form()
|
||||
args = request.query_params
|
||||
background_tasks.add_task(start_webhook_chain, db, body, form, args)
|
||||
background_tasks.add_task(start_webhook_chain, body, form, args)
|
||||
return schemas.Response(success=True)
|
||||
|
||||
|
||||
@router.get("/", summary="Webhook消息响应", response_model=schemas.Response)
|
||||
async def webhook_message(background_tasks: BackgroundTasks,
|
||||
token: str, request: Request,
|
||||
db: Session = Depends(get_db)) -> Any:
|
||||
token: str, request: Request) -> Any:
|
||||
"""
|
||||
Webhook响应
|
||||
"""
|
||||
if token != settings.API_TOKEN:
|
||||
return schemas.Response(success=False, message="token认证不通过")
|
||||
args = request.query_params
|
||||
background_tasks.add_task(start_webhook_chain, db, None, None, args)
|
||||
background_tasks.add_task(start_webhook_chain, None, None, args)
|
||||
return schemas.Response(success=True)
|
||||
|
@ -2,9 +2,10 @@ from typing import Optional, List
|
||||
|
||||
from app import schemas
|
||||
from app.chain import ChainBase
|
||||
from app.utils.singleton import Singleton
|
||||
|
||||
|
||||
class DashboardChain(ChainBase):
|
||||
class DashboardChain(ChainBase, metaclass=Singleton):
|
||||
"""
|
||||
各类仪表板统计处理链
|
||||
"""
|
||||
|
@ -8,10 +8,11 @@ from app.core.config import settings
|
||||
from app.log import logger
|
||||
from app.schemas import Notification, MessageChannel
|
||||
from app.utils.http import RequestUtils
|
||||
from app.utils.singleton import Singleton
|
||||
from app.utils.system import SystemUtils
|
||||
|
||||
|
||||
class SystemChain(ChainBase):
|
||||
class SystemChain(ChainBase, metaclass=Singleton):
|
||||
"""
|
||||
系统级处理链
|
||||
"""
|
||||
|
@ -4,10 +4,11 @@ from typing import Any
|
||||
from app.chain import ChainBase
|
||||
from app.schemas import Notification
|
||||
from app.schemas.types import EventType, MediaImageType, MediaType, NotificationType
|
||||
from app.utils.singleton import Singleton
|
||||
from app.utils.web import WebUtils
|
||||
|
||||
|
||||
class WebhookChain(ChainBase):
|
||||
class WebhookChain(ChainBase, metaclass=Singleton):
|
||||
"""
|
||||
Webhook处理链
|
||||
"""
|
||||
|
@ -1,6 +1,7 @@
|
||||
import importlib
|
||||
import threading
|
||||
import traceback
|
||||
from threading import Thread, Event
|
||||
from threading import Thread
|
||||
from typing import Any, Union, Dict
|
||||
|
||||
from app.chain import ChainBase
|
||||
@ -39,7 +40,7 @@ class Command(metaclass=Singleton):
|
||||
_commands = {}
|
||||
|
||||
# 退出事件
|
||||
_event = Event()
|
||||
_event = threading.Event()
|
||||
|
||||
def __init__(self):
|
||||
# 数据库连接
|
||||
@ -135,25 +136,25 @@ class Command(metaclass=Singleton):
|
||||
"data": {}
|
||||
},
|
||||
"/clear_cache": {
|
||||
"func": SystemChain(self._db).remote_clear_cache,
|
||||
"func": SystemChain().remote_clear_cache,
|
||||
"description": "清理缓存",
|
||||
"category": "管理",
|
||||
"data": {}
|
||||
},
|
||||
"/restart": {
|
||||
"func": SystemChain(self._db).restart,
|
||||
"func": SystemChain().restart,
|
||||
"description": "重启系统",
|
||||
"category": "管理",
|
||||
"data": {}
|
||||
},
|
||||
"/version": {
|
||||
"func": SystemChain(self._db).version,
|
||||
"func": SystemChain().version,
|
||||
"description": "当前版本",
|
||||
"category": "管理",
|
||||
"data": {}
|
||||
},
|
||||
"/update": {
|
||||
"func": SystemChain(self._db).update,
|
||||
"func": SystemChain().update,
|
||||
"description": "更新系统",
|
||||
"category": "管理",
|
||||
"data": {}
|
||||
@ -179,7 +180,7 @@ class Command(metaclass=Singleton):
|
||||
# 启动事件处理线程
|
||||
self._thread.start()
|
||||
# 重启msg
|
||||
SystemChain(self._db).restart_finish()
|
||||
SystemChain().restart_finish()
|
||||
|
||||
def __run(self):
|
||||
"""
|
||||
|
@ -9,9 +9,9 @@ Engine = create_engine(f"sqlite:///{settings.CONFIG_PATH}/user.db",
|
||||
echo=False,
|
||||
poolclass=QueuePool,
|
||||
pool_size=1024,
|
||||
pool_recycle=600,
|
||||
pool_recycle=3600,
|
||||
pool_timeout=180,
|
||||
max_overflow=0,
|
||||
max_overflow=10,
|
||||
connect_args={"timeout": 60})
|
||||
# 会话工厂
|
||||
SessionFactory = sessionmaker(autocommit=False, autoflush=False, bind=Engine)
|
||||
|
@ -80,7 +80,7 @@ class MoviePilotUpdateNotify(_PluginBase):
|
||||
return
|
||||
|
||||
# 本地版本
|
||||
local_version = SystemChain(self.db).get_local_version()
|
||||
local_version = SystemChain().get_local_version()
|
||||
if release_version == local_version:
|
||||
logger.info(f"当前版本:{local_version} 远程版本:{release_version} 停止运行")
|
||||
return
|
||||
@ -98,7 +98,7 @@ class MoviePilotUpdateNotify(_PluginBase):
|
||||
# 自动更新
|
||||
if self._update:
|
||||
logger.info("开始执行自动更新…")
|
||||
SystemChain(self.db).update()
|
||||
SystemChain().update()
|
||||
|
||||
@staticmethod
|
||||
def __get_release_version():
|
||||
|
@ -1,4 +1,5 @@
|
||||
import logging
|
||||
import threading
|
||||
from datetime import datetime, timedelta
|
||||
from typing import List
|
||||
|
||||
@ -39,6 +40,8 @@ class Scheduler(metaclass=Singleton):
|
||||
executors={
|
||||
'default': ThreadPoolExecutor(20)
|
||||
})
|
||||
# 退出事件
|
||||
_event = threading.Event()
|
||||
|
||||
def __init__(self):
|
||||
# 数据库连接
|
||||
@ -258,6 +261,7 @@ class Scheduler(metaclass=Singleton):
|
||||
"""
|
||||
关闭定时服务
|
||||
"""
|
||||
self._event.set()
|
||||
if self._scheduler.running:
|
||||
self._scheduler.shutdown()
|
||||
if self._db:
|
||||
|
Loading…
x
Reference in New Issue
Block a user