新增 消息定时推送功能

This commit is contained in:
liuwei
2025-06-10 11:37:08 +08:00
parent ac29a826ee
commit 21130c943d

View File

@@ -5,6 +5,7 @@ from loguru import logger
from base.plugin_common.message_plugin_interface import MessagePluginInterface
from base.plugin_common.plugin_interface import PluginStatus
from db.connection import DBConnectionManager
from db.task_db import TaskDBOperator
from utils.decorator.async_job import async_job
from utils.decorator.plugin_decorators import plugin_stats_decorator
@@ -55,17 +56,17 @@ class MessagePushTask(MessagePluginInterface):
# 保存上下文对象
self.event_system = context.get("event_system")
self.db_manager = context.get("db_manager")
self.db_manager = DBConnectionManager.get_instance()
# 初始化组件
self.db = TaskDBOperator(self.db_manager)
async_job.every_seconds(5)(self.process_scheduled_tasks)
# 初始化数据库表
if not self.db.init_tables():
self.LOG.error("初始化数据库表失败")
return False
async_job.every_seconds(5)(self.process_scheduled_tasks)
# 加载配置
self._commands = self._config.get("MessagePush", {}).get("command", ["推送", "消息推送"])
self.command_format = self._config.get("MessagePush", {}).get("command-format", "推送 消息内容")
@@ -242,7 +243,7 @@ class MessagePushTask(MessagePluginInterface):
self.LOG.error(f"处理定时任务出错: {e}")
def _calculate_next_schedule_time(self, current_time: datetime, interval: str, end_time: datetime = None) -> \
Optional[datetime]:
Optional[datetime]:
"""计算下次执行时间
Args: