feat(schedule): move system jobs to DB-driven config and dashboard management

This commit is contained in:
liuwei
2026-04-16 14:54:23 +08:00
parent cb0d11e657
commit 66a9b7c4a3
10 changed files with 1147 additions and 208 deletions

62
main.py
View File

@@ -6,7 +6,6 @@ import threading
from admin.GlancesMonitor import GlancesMonitor
from utils.decorator.async_job import async_job
from configuration import Config
from plugins.xiuren_image.images_cache import ImageCacheManager
from robot import Robot
from loguru import logger
@@ -114,63 +113,10 @@ def main():
def jobs(robot: Robot):
# ✅ 每天 8:30 发送百度新闻
@async_job.at_times(["08:30"])
async def news_baidu_report_auto_job():
await robot.news_baidu_report_auto()
# ✅ 每天 10:30 推送 Epic 免费游戏
@async_job.every_weekday_time(weekday=4, time_str="10:00") # 0=周一4=周五
async def epic_job():
await robot.send_epic_free_games()
# ✅ 每天 02:30 从 redis 写入 sqlite
@async_job.at_times(["02:30"])
async def msg_count_to_db_job():
await robot.message_count_to_db()
# ✅ 每天 09:30 从 sqlite 读取并发送群排行
@async_job.at_times(["09:30"])
async def msg_ranking_job():
await robot.generate_and_send_ranking()
# ✅ 每天 15:30 发涩图 PDF
@async_job.at_times(["15:30"])
async def sehuatang_pdf_job():
await robot.generate_sehuatang_pdf()
# ✅ 每天 01:30 下载秀人网帖子
@async_job.at_times(["01:30"])
async def xiuren_download_job():
await robot.xiu_ren_download_task()
# ✅ 每天 01:30 下载秀人网帖子
@async_job.at_times(["2:30"])
async def shenshiR15_download_job():
await robot.shen_shi_download_task()
# ✅ 每天 17:30 发秀人 PDF如果启用
# @async_job.at_times(["17:30"])
# async def xiuren_pdf_send_job():
# await robot.xiu_ren_pdf_send()
# ✅ 每 3 小时登录验证
@async_job.at_times(["14:43"])
async def login_check_job():
await robot.login_twice_auto_auth()
@async_job.at_times(["05:00"])
async def update_image_cache_job():
logger.info("开始执行图片缓存更新任务")
manager = ImageCacheManager("/mnt/nfs_share") # 替换为你的图片目录
await manager.update_image_cache()
logger.info("图片缓存更新完成")
# ✅ 每5分钟处理一次待下载的图片/表情消息(串行处理,避免数据库锁竞争)
@async_job.every_minutes(5)
async def process_pending_images_job():
if hasattr(robot, 'message_storage') and robot.message_storage:
await robot.message_storage.process_pending_images(minutes_ago=10, batch_size=20)
# 系统级定时任务统一改为数据库驱动,不再在 main.py 里硬编码维护。
# 这里保留入口,只负责按表配置重新加载,便于运行时刷新。
if hasattr(robot, "system_job_loader") and robot.system_job_loader:
robot.system_job_loader.reload_from_db()