diff --git a/app/chain/__init__.py b/app/chain/__init__.py index c9bae441..34a86526 100644 --- a/app/chain/__init__.py +++ b/app/chain/__init__.py @@ -300,3 +300,9 @@ class ChainBase(AbstractSingleton, metaclass=Singleton): 注册菜单命令 """ return self.run_module("register_commands", commands=commands) + + def scheduler_job(self) -> None: + """ + 定时任务,每10分钟调用一次,模块实现该接口以实现定时服务 + """ + return self.run_module("scheduler_job") diff --git a/app/modules/themoviedb/__init__.py b/app/modules/themoviedb/__init__.py index 3bdce7c7..07c48cca 100644 --- a/app/modules/themoviedb/__init__.py +++ b/app/modules/themoviedb/__init__.py @@ -557,3 +557,9 @@ class TheMovieDbModule(_ModuleBase): xml_str = doc.toprettyxml(indent=" ", encoding="utf-8") file_path.write_bytes(xml_str) logger.info(f"NFO文件已保存:{file_path}") + + def scheduler_job(self) -> None: + """ + 定时任务,每10分钟调用一次 + """ + self.cache.save() diff --git a/app/scheduler.py b/app/scheduler.py index 765c2636..dc998098 100644 --- a/app/scheduler.py +++ b/app/scheduler.py @@ -5,6 +5,7 @@ import pytz from apscheduler.executors.pool import ThreadPoolExecutor from apscheduler.schedulers.background import BackgroundScheduler +from app.chain import ChainBase from app.chain.cookiecloud import CookieCloudChain from app.chain.douban import DoubanChain from app.chain.subscribe import SubscribeChain @@ -21,6 +22,10 @@ scheduler_logger = logging.getLogger('apscheduler') scheduler_logger.setLevel(logging.WARNING) +class SchedulerChain(ChainBase): + pass + + class Scheduler(metaclass=Singleton): """ 定时任务管理 @@ -56,6 +61,9 @@ class Scheduler(metaclass=Singleton): # 下载器文件转移(每5分钟) self._scheduler.add_job(TransferChain().process, "interval", minutes=5) + # 公共定时服务 + self._scheduler.add_job(SchedulerChain().scheduler_job, "interval", minutes=10) + # 打印服务 logger.debug(self._scheduler.print_jobs())