系统业务任务插件化迁移:下沉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:
liuwei
2026-04-16 16:05:59 +08:00
parent 1166323ab5
commit 9652c2594e
13 changed files with 748 additions and 73 deletions

View File

@@ -3,8 +3,6 @@ from __future__ import annotations
from typing import Any, Awaitable, Callable, Dict, List
from loguru import logger
from db.system_job_db import SystemJobDBOperator
from utils.decorator.async_job import async_job
@@ -16,22 +14,6 @@ def get_system_job_definitions(robot) -> List[Dict[str, Any]]:
调度时间、启停状态全部从数据库 t_system_jobs 读取。
"""
return [
{
"job_key": "news_baidu_report_auto",
"name": "百度新闻日报",
"description": "每天 08:30 推送百度新闻",
"trigger_type": "at_times",
"trigger_config": {"time_list": ["08:30"]},
"handler": robot.news_baidu_report_auto,
},
{
"job_key": "epic_free_games",
"name": "Epic 免费游戏推送",
"description": "每周五 10:00 推送 Epic 免费游戏",
"trigger_type": "every_weekday_time",
"trigger_config": {"weekday": 4, "time_str": "10:00"},
"handler": robot.send_epic_free_games,
},
{
"job_key": "message_count_to_db",
"name": "消息计数入库",
@@ -40,38 +22,6 @@ def get_system_job_definitions(robot) -> List[Dict[str, Any]]:
"trigger_config": {"time_list": ["02:30"]},
"handler": robot.message_count_to_db,
},
{
"job_key": "message_ranking_push",
"name": "群消息排行推送",
"description": "每天 09:30 生成并发送群消息排行",
"trigger_type": "at_times",
"trigger_config": {"time_list": ["09:30"]},
"handler": robot.generate_and_send_ranking,
},
{
"job_key": "sehuatang_pdf_push",
"name": "涩图 PDF 推送",
"description": "每天 15:30 生成并发送涩图 PDF",
"trigger_type": "at_times",
"trigger_config": {"time_list": ["15:30"]},
"handler": robot.generate_sehuatang_pdf,
},
{
"job_key": "xiuren_download",
"name": "秀人网下载任务",
"description": "每天 01:30 执行秀人网下载任务",
"trigger_type": "at_times",
"trigger_config": {"time_list": ["01:30"]},
"handler": robot.xiu_ren_download_task,
},
{
"job_key": "shenshi_r15_download",
"name": "绅士 R15 下载任务",
"description": "每天 02:30 执行绅士 R15 下载任务",
"trigger_type": "at_times",
"trigger_config": {"time_list": ["02:30"]},
"handler": robot.shen_shi_download_task,
},
{
"job_key": "login_check",
"name": "登录状态巡检",
@@ -80,14 +30,6 @@ def get_system_job_definitions(robot) -> List[Dict[str, Any]]:
"trigger_config": {"time_list": ["14:43"]},
"handler": robot.login_twice_auto_auth,
},
{
"job_key": "update_image_cache",
"name": "图片缓存更新",
"description": "每天 05:00 扫描并更新图片缓存",
"trigger_type": "at_times",
"trigger_config": {"time_list": ["05:00"]},
"handler": _build_image_cache_handler(robot),
},
{
"job_key": "process_pending_images",
"name": "待下载图片补偿处理",
@@ -98,19 +40,6 @@ def get_system_job_definitions(robot) -> List[Dict[str, Any]]:
},
]
def _build_image_cache_handler(robot) -> Callable[[], Awaitable[None]]:
async def _handler():
from plugins.xiuren_image.images_cache import ImageCacheManager
logger.info("开始执行图片缓存更新任务")
manager = ImageCacheManager("/mnt/nfs_share")
await manager.update_image_cache()
logger.info("图片缓存更新完成")
return _handler
def _build_process_pending_images_handler(robot) -> Callable[[], Awaitable[None]]:
async def _handler():
if hasattr(robot, "message_storage") and robot.message_storage: