Skip to content

Commit d0677ed

Browse files
committed
fix 优雅停止
1 parent f0aaecd commit d0677ed

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

app/chain/subscribe.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ def search(self, sid: Optional[int] = None, state: Optional[str] = 'N', manual:
360360
# 过滤搜索结果
361361
matched_contexts = []
362362
for context in contexts:
363+
if global_vars.is_system_stopped:
364+
break
363365
torrent_meta = context.meta_info
364366
torrent_info = context.torrent_info
365367
torrent_mediainfo = context.media_info
@@ -554,8 +556,12 @@ def match(self, torrents: Dict[str, List[Context]]):
554556
# 预识别所有未识别的种子
555557
processed_torrents: Dict[str, List[Context]] = {}
556558
for domain, contexts in torrents.items():
559+
if global_vars.is_system_stopped:
560+
break
557561
processed_torrents[domain] = []
558562
for context in contexts:
563+
if global_vars.is_system_stopped:
564+
break
559565
# 如果种子未识别,尝试识别
560566
if not context.media_info or (not context.media_info.tmdb_id
561567
and not context.media_info.douban_id):
@@ -626,6 +632,8 @@ def match(self, torrents: Dict[str, List[Context]]):
626632
continue
627633
logger.debug(f'开始匹配站点:{domain},共缓存了 {len(contexts)} 个种子...')
628634
for context in contexts:
635+
if global_vars.is_system_stopped:
636+
break
629637
# 提取信息
630638
_context = copy.copy(context)
631639
torrent_meta = _context.meta_info
@@ -867,6 +875,8 @@ def follow():
867875
success_count = 0
868876
subscribeoper = SubscribeOper()
869877
for share_sub in share_subs:
878+
if global_vars.is_system_stopped:
879+
break
870880
uid = share_sub.get("share_uid")
871881
if uid and uid in follow_users:
872882
# 订阅已存在则跳过

app/startup/lifecycle.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from fastapi import FastAPI
55

66
from app.chain.system import SystemChain
7-
from app.core.config import global_vars
87
from app.startup.command_initializer import init_command, stop_command, restart_command
98
from app.startup.memory_initializer import init_memory_manager, stop_memory_manager
109
from app.startup.modules_initializer import init_modules, stop_modules
@@ -62,8 +61,6 @@ async def lifespan(app: FastAPI):
6261
yield
6362
finally:
6463
print("Shutting down...")
65-
# 停止信号
66-
global_vars.stop_system()
6764
# 取消同步插件任务
6865
try:
6966
sync_plugins_task.cancel()

0 commit comments

Comments
 (0)