modify: 目录结构整理
This commit is contained in:
parent
149855b867
commit
3f03290e4f
@ -1,3 +1,4 @@
|
|||||||
from .task_mounter import TaskMounter
|
from .task_mounter import TaskMounter
|
||||||
|
from .listen_mounter import ListenMounter
|
||||||
|
|
||||||
__all__ = ["TaskMounter"]
|
__all__ = ["TaskMounter", "ListenMounter"]
|
||||||
@ -1,42 +0,0 @@
|
|||||||
from typing import Callable, List
|
|
||||||
|
|
||||||
|
|
||||||
class BaseMounter:
|
|
||||||
@classmethod
|
|
||||||
def mount_(cls, function: Callable):
|
|
||||||
setattr(cls, function.__name__, function)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def mount(meta: dict = {}):
|
|
||||||
"""带参数的装饰器"""
|
|
||||||
def decorator(function: Callable):
|
|
||||||
# 使用自定义名称或函数原名
|
|
||||||
function.meta = meta # type: ignore
|
|
||||||
setattr(BaseMounter, function.__name__, function)
|
|
||||||
return function
|
|
||||||
return decorator
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_function(cls, name: str):
|
|
||||||
return getattr(cls, name, None)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_task_list(cls) -> List[str]:
|
|
||||||
"""获取所有挂载的任务函数名称列表"""
|
|
||||||
task_list = []
|
|
||||||
|
|
||||||
# 遍历类属性字典
|
|
||||||
for attr_name, attr_value in vars(cls).items():
|
|
||||||
# 过滤条件:
|
|
||||||
# 1. 必须是可调用对象(函数)
|
|
||||||
# 2. 不是类自带的特殊方法(非双下划线开头)
|
|
||||||
# 3. 不是类方法本身(如 mount_, get_task_list 等)
|
|
||||||
if (
|
|
||||||
callable(attr_value)
|
|
||||||
and not attr_name.startswith("__")
|
|
||||||
and attr_name not in ["mount_", "mount", "get_function", "get_task_list"]
|
|
||||||
):
|
|
||||||
task_list.append(attr_name)
|
|
||||||
|
|
||||||
return task_list
|
|
||||||
|
|
||||||
@ -1,6 +1,5 @@
|
|||||||
from ..mounter.listen_mounter import ListenMounter
|
from ..mounter.listen_mounter import ListenMounter
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import threading
|
|
||||||
|
|
||||||
|
|
||||||
class ListenOperation:
|
class ListenOperation:
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import threading
|
|||||||
|
|
||||||
|
|
||||||
class TaskScheduler:
|
class TaskScheduler:
|
||||||
def __init__(self, queue_operation: QueueOperation, task_thread_num: int = 1):
|
def __init__(self, queue_operation: QueueOperation, task_thread_num: int = 2):
|
||||||
self.task_thread_num = task_thread_num
|
self.task_thread_num = task_thread_num
|
||||||
self.is_running = False
|
self.is_running = False
|
||||||
self.executor = ThreadPoolExecutor(max_workers=task_thread_num) # 并行执行任务
|
self.executor = ThreadPoolExecutor(max_workers=task_thread_num) # 并行执行任务
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user