Skip to content

Commit d48c14c

Browse files
committed
update renamer monitor
1 parent b7b3026 commit d48c14c

18 files changed

Lines changed: 324 additions & 365 deletions

File tree

backend/src/module/checker/checker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def check_database() -> bool:
5151

5252
@staticmethod
5353
def check_downloader() -> bool:
54-
return DownloadClient.is_login
54+
return DownloadClient.login_success_event.is_set()
5555

5656
@staticmethod
5757
def check_img_cache() -> bool:
@@ -65,4 +65,5 @@ def check_img_cache() -> bool:
6565

6666
if __name__ == "__main__":
6767
import asyncio
68+
pass
6869

backend/src/module/core/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
# 导入服务模块以确保服务注册
21
from .services import RSSService, DownloadService
3-
from .service_registry import service_registry
42
from .aiocore import AsyncApplicationCore, app_core
53
from .program import Program
64

75
__all__ = [
86
'RSSService',
97
'DownloadService',
10-
'service_registry',
118
'AsyncApplicationCore',
129
'app_core',
1310
'Program'

backend/src/module/core/aiocore.py

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
from contextlib import asynccontextmanager
44
from typing import Any
55

6-
from .events import EventBus
7-
from .service_registry import service_registry
6+
from module.utils.events import EventBus
87
from .task_manager import TaskManager
98

109
logger = logging.getLogger(__name__)
@@ -21,6 +20,8 @@ def __init__(self):
2120
self.event_bus = EventBus()
2221
self.services = []
2322
self._download_monitor = None
23+
self._rename_monitor = None
24+
self._notification_monitor = None
2425
self._running: bool = False
2526
self._initialized: bool = False
2627

@@ -33,21 +34,18 @@ async def initialize(self) -> None:
3334
logger.info("[AsyncCore] 开始初始化...")
3435

3536
try:
36-
# 确保服务已注册(导入服务模块)
37+
# 创建服务实例
3738
from .services import RSSService, DownloadService
38-
39-
# 从服务注册表获取服务实例
40-
self.services = service_registry.create_service_instances()
39+
40+
self.services = [
41+
DownloadService(),
42+
RSSService(),
43+
]
4144

4245
# 初始化所有服务
4346
for service in self.services:
4447
await service.initialize()
4548
logger.debug(f"[AsyncCore] 服务 {service.name} 初始化完成")
46-
## download服务需要特殊处理,要注入event_bus
47-
download_service = service_registry.get_service_instance("download")
48-
if download_service:
49-
download_service.set_event_bus(self.event_bus)
50-
logger.debug("[AsyncCore] 已为下载服务注入事件总线")
5149

5250
# 注册任务到任务管理器
5351
await self._register_tasks()
@@ -80,26 +78,43 @@ async def _register_event_handlers(self) -> None:
8078
"""注册事件处理器"""
8179
try:
8280
from module.downloader.download_monitor import DownloadMonitor
83-
from module.core.events import EventType
81+
from module.manager.rename_monitor import RenameMonitor
82+
from module.notification.notification_monitor import NotificationMonitor
83+
from module.utils.events import EventType
8484

85-
# 创建并注册 DownloadMonitor,注入 event_bus
85+
# 创建并注册 DownloadMonitor
8686
self._download_monitor = DownloadMonitor(event_bus=self.event_bus)
8787
self.event_bus.subscribe(
8888
EventType.DOWNLOAD_STARTED,
8989
self._download_monitor.handle_download_started,
9090
)
9191
logger.info("[AsyncCore] 已注册 DownloadMonitor 事件处理器")
9292

93-
# 为下载服务设置监控器和事件总线
93+
# 创建并注册 RenameMonitor
94+
self._rename_monitor = RenameMonitor(event_bus=self.event_bus)
95+
await self._rename_monitor.initialize()
96+
self.event_bus.subscribe(
97+
EventType.DOWNLOAD_COMPLETED,
98+
self._rename_monitor.handle_download_completed,
99+
)
100+
logger.info("[AsyncCore] 已注册 RenameMonitor 事件处理器")
101+
102+
# 创建并注册 NotificationMonitor
103+
self._notification_monitor = NotificationMonitor(event_bus=self.event_bus)
104+
await self._notification_monitor.initialize()
105+
self.event_bus.subscribe(
106+
EventType.RENAME_COMPLETED,
107+
self._notification_monitor.handle_rename_completed,
108+
)
109+
logger.info("[AsyncCore] 已注册 NotificationMonitor 事件处理器")
110+
111+
# 为下载服务设置事件总线
94112
for service in self.services:
95113
if service.name == "download" and hasattr(
96114
service, "_download_controller"
97115
):
98-
service._download_controller.set_download_monitor(
99-
self._download_monitor
100-
)
101116
service._download_controller.set_event_bus(self.event_bus)
102-
logger.debug("[AsyncCore] 已为下载服务设置监控器和事件总线")
117+
logger.debug("[AsyncCore] 已为下载服务设置事件总线")
103118

104119
except Exception as e:
105120
logger.error(f"[AsyncCore] 注册事件处理器失败: {e}")
@@ -140,14 +155,28 @@ async def stop(self) -> None:
140155
except Exception as e:
141156
logger.error(f"[AsyncCore] 任务管理器关闭失败: {e}")
142157

143-
# 关闭下载监控器
158+
# 关闭监控器
144159
try:
145160
if hasattr(self, "_download_monitor") and self._download_monitor:
146161
await self._download_monitor.shutdown()
147162
logger.debug("[AsyncCore] 下载监控器已关闭")
148163
except Exception as e:
149164
logger.error(f"[AsyncCore] 下载监控器关闭失败: {e}")
150165

166+
try:
167+
if hasattr(self, "_rename_monitor") and self._rename_monitor:
168+
await self._rename_monitor.shutdown()
169+
logger.debug("[AsyncCore] 重命名监控器已关闭")
170+
except Exception as e:
171+
logger.error(f"[AsyncCore] 重命名监控器关闭失败: {e}")
172+
173+
try:
174+
if hasattr(self, "_notification_monitor") and self._notification_monitor:
175+
await self._notification_monitor.shutdown()
176+
logger.debug("[AsyncCore] 通知监控器已关闭")
177+
except Exception as e:
178+
logger.error(f"[AsyncCore] 通知监控器关闭失败: {e}")
179+
151180
# 清理服务资源
152181
await self._cleanup_services()
153182

@@ -176,9 +205,15 @@ def get_status(self) -> dict[str, Any]:
176205
"event_bus": self.event_bus.get_subscribers_count(),
177206
}
178207

179-
# 添加下载监控器状态
208+
# 添加监控器状态
180209
if self._download_monitor:
181210
status["download_monitor"] = self._download_monitor.get_monitoring_status()
211+
212+
status["monitors"] = {
213+
"download_monitor": bool(self._download_monitor),
214+
"rename_monitor": bool(self._rename_monitor),
215+
"notification_monitor": bool(self._notification_monitor),
216+
}
182217

183218
return status
184219

backend/src/module/core/service_registry.py

Lines changed: 0 additions & 173 deletions
This file was deleted.

0 commit comments

Comments
 (0)