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