系统业务任务插件化迁移:下沉7项非刚需任务并接入平滑迁移
- 系统任务保留刚需三项:登录巡检、消息计数入库、媒体补偿处理;移除新闻/Epic/排行/PDF/秀人维护等业务型系统任务定义\n- 新增 daily_news、epic_free、daily_ranking、sehuatang_push 四个插件,将原系统业务任务改为插件可调度动作\n- 扩展 xiuren_image 插件调度动作,新增秀人下载、绅士R15下载、图片缓存更新三项维护任务\n- 新增系统任务到插件任务的幂等迁移逻辑:按旧 job_key 映射到插件 action,同步 trigger_type/trigger_config/enabled,并通过 payload 标记防止反复覆盖\n- 在 Robot 启动流程中接入迁移执行与重载,并清理已迁移的历史系统任务记录,避免后台双份维护\n- 扩展插件调度数据库操作:支持按 plugin_name + action_key 精确查询,便于迁移与对账
This commit is contained in:
@@ -3,12 +3,15 @@ from pathlib import Path
|
||||
from loguru import logger
|
||||
import os
|
||||
import base64
|
||||
import asyncio
|
||||
from typing import Dict, Any, List, Optional, Tuple
|
||||
|
||||
from db.connection import DBConnectionManager
|
||||
from base.plugin_common.message_plugin_interface import MessagePluginInterface
|
||||
from base.plugin_common.plugin_interface import PluginStatus
|
||||
from plugins.xiuren_image.images_cache import ImageCacheManager
|
||||
from plugins.xiuren_image.meitu_dl import meitu_dowload_pub_pic
|
||||
from plugins.xiuren_image.shenshi_r15 import run_daily_job
|
||||
from utils.decorator.plugin_decorators import plugin_stats_decorator
|
||||
from utils.decorator.rate_limit_decorator import group_feature_rate_limit
|
||||
from utils.revoke.message_auto_revoke import MessageAutoRevoke
|
||||
@@ -234,11 +237,96 @@ class XiurenImagePlugin(MessagePluginInterface):
|
||||
"target_config": {},
|
||||
"payload": {"max_per_group": 1},
|
||||
"default_enabled": False,
|
||||
},
|
||||
{
|
||||
"action_key": "resource_xiuren_download",
|
||||
"name": "秀人资源下载",
|
||||
"description": "执行秀人资源下载维护任务",
|
||||
"trigger_type": "at_times",
|
||||
"trigger_config": {"time_list": ["01:30"]},
|
||||
"target_scope": "all_enabled_groups",
|
||||
"target_config": {},
|
||||
"payload": {},
|
||||
"default_enabled": True,
|
||||
},
|
||||
{
|
||||
"action_key": "resource_shenshi_r15_download",
|
||||
"name": "绅士R15资源下载",
|
||||
"description": "执行绅士R15资源下载维护任务",
|
||||
"trigger_type": "at_times",
|
||||
"trigger_config": {"time_list": ["02:30"]},
|
||||
"target_scope": "all_enabled_groups",
|
||||
"target_config": {},
|
||||
"payload": {},
|
||||
"default_enabled": True,
|
||||
},
|
||||
{
|
||||
"action_key": "resource_update_image_cache",
|
||||
"name": "图片缓存更新",
|
||||
"description": "扫描并更新图片缓存",
|
||||
"trigger_type": "at_times",
|
||||
"trigger_config": {"time_list": ["05:00"]},
|
||||
"target_scope": "all_enabled_groups",
|
||||
"target_config": {},
|
||||
"payload": {},
|
||||
"default_enabled": True,
|
||||
}
|
||||
]
|
||||
|
||||
async def run_scheduled_action(self, action_key: str, context: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""执行插件定时动作。"""
|
||||
if action_key == "resource_xiuren_download":
|
||||
try:
|
||||
# 历史逻辑为同步下载任务,这里放到线程池执行,避免阻塞调度主循环。
|
||||
await asyncio.to_thread(meitu_dowload_pub_pic)
|
||||
return {
|
||||
"success": True,
|
||||
"summary": "秀人资源下载任务执行完成",
|
||||
"detail": {},
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
"success": False,
|
||||
"summary": f"秀人资源下载失败: {e}",
|
||||
"detail": {"error": str(e)},
|
||||
}
|
||||
|
||||
if action_key == "resource_shenshi_r15_download":
|
||||
try:
|
||||
await asyncio.to_thread(run_daily_job)
|
||||
return {
|
||||
"success": True,
|
||||
"summary": "绅士R15资源下载任务执行完成",
|
||||
"detail": {},
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
"success": False,
|
||||
"summary": f"绅士R15资源下载失败: {e}",
|
||||
"detail": {"error": str(e)},
|
||||
}
|
||||
|
||||
if action_key == "resource_update_image_cache":
|
||||
try:
|
||||
if not self.image_cache_manager:
|
||||
return {
|
||||
"success": False,
|
||||
"summary": "缓存管理器未初始化",
|
||||
"detail": {},
|
||||
}
|
||||
await self.image_cache_manager.update_image_cache()
|
||||
return {
|
||||
"success": True,
|
||||
"summary": "图片缓存更新完成",
|
||||
"detail": {"image_folder": self.image_folder},
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
"success": False,
|
||||
"summary": f"图片缓存更新失败: {e}",
|
||||
"detail": {"error": str(e)},
|
||||
}
|
||||
|
||||
if action_key != "daily_push":
|
||||
return {
|
||||
"success": False,
|
||||
|
||||
Reference in New Issue
Block a user