Skip to content

Commit

Permalink
Merge pull request #2792 from InfinityPacer/feature/event
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp authored Sep 30, 2024
2 parents 666f9a5 + 0ca4223 commit ee455ac
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/core/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,16 @@ def check(self, etype: Union[EventType, ChainEventType]) -> bool:
:return: 返回是否存在可用的处理器
"""
if isinstance(etype, ChainEventType):
handlers = self.__chain_subscribers.get(etype, [])
handlers = self.__chain_subscribers.get(etype, {})
return any(
self.__is_handler_enabled(handler)
for _, handler in handlers
for _, handler in handlers.values()
)
else:
handlers = self.__broadcast_subscribers.get(etype, [])
handlers = self.__broadcast_subscribers.get(etype, {})
return any(
self.__is_handler_enabled(handler)
for handler in handlers
for handler in handlers.values()
)

def send_event(self, etype: Union[EventType, ChainEventType], data: Optional[Dict] = None,
Expand Down
3 changes: 3 additions & 0 deletions app/core/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
from typing import Generator, Optional, Tuple, Any

from app.core.config import settings
from app.core.event import eventmanager
from app.helper.module import ModuleHelper
from app.log import logger
from app.schemas.types import EventType
from app.utils.object import ObjectUtils
from app.utils.singleton import Singleton

Expand Down Expand Up @@ -67,6 +69,7 @@ def reload(self):
"""
self.stop()
self.load_modules()
eventmanager.send_event(etype=EventType.ModuleReload, data={})

def test(self, modleid: str) -> Tuple[bool, str]:
"""
Expand Down
2 changes: 2 additions & 0 deletions app/schemas/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class EventType(Enum):
SystemError = "system.error"
# 刮削元数据
MetadataScrape = "metadata.scrape"
# 模块需要重载
ModuleReload = "module.reload"


# 同步链式事件
Expand Down

0 comments on commit ee455ac

Please sign in to comment.