mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-08-29 03:56:43 +08:00
refactor(scheduler): 缓存清理改为仅手动执行
移除 clear_cache 的 add_job 注册,不再自动定时执行。 在 _jobs 中标记 manual=True 并补充 provider_name, list() 新增手动任务展示段,未调度的手动任务也能在 UI 中显示和手动触发。
This commit is contained in:
+22
-10
@@ -475,7 +475,9 @@ class Scheduler(ConfigReloadMixin, metaclass=SingletonClass):
|
||||
"clear_cache": {
|
||||
"name": "缓存清理",
|
||||
"func": self.clear_cache,
|
||||
"provider_name": "[系统]",
|
||||
"running": False,
|
||||
"manual": True,
|
||||
},
|
||||
"data_cleanup": {
|
||||
"name": "数据表清理",
|
||||
@@ -682,16 +684,6 @@ class Scheduler(ConfigReloadMixin, metaclass=SingletonClass):
|
||||
kwargs={"job_id": "scheduler_job"},
|
||||
)
|
||||
|
||||
# 缓存清理服务
|
||||
self._scheduler.add_job(
|
||||
self.start,
|
||||
"interval",
|
||||
id="clear_cache",
|
||||
name="缓存清理",
|
||||
hours=24,
|
||||
kwargs={"job_id": "clear_cache"},
|
||||
)
|
||||
|
||||
# 数据表清理服务,每天凌晨执行一次
|
||||
if settings.DATA_CLEANUP_ENABLE:
|
||||
self._scheduler.add_job(
|
||||
@@ -1524,6 +1516,26 @@ class Scheduler(ConfigReloadMixin, metaclass=SingletonClass):
|
||||
progress_detail=progress,
|
||||
)
|
||||
)
|
||||
# 仅手动执行的任务(未注册到调度器)
|
||||
for job_id, service in self._jobs.items():
|
||||
if not service.get("manual"):
|
||||
continue
|
||||
if job_id in added:
|
||||
continue
|
||||
added.append(job_id)
|
||||
progress = self.get_progress(job_id)
|
||||
schedulers.append(
|
||||
schemas.ScheduleInfo(
|
||||
id=job_id,
|
||||
name=service.get("name"),
|
||||
provider=service.get("provider_name", "[系统]"),
|
||||
status="等待",
|
||||
progress=progress.value if progress else 0,
|
||||
progress_text=progress.text if progress else None,
|
||||
progress_enable=progress.enable if progress else False,
|
||||
progress_detail=progress,
|
||||
)
|
||||
)
|
||||
return schedulers
|
||||
|
||||
def stop(self):
|
||||
|
||||
@@ -45,8 +45,8 @@ def test_scheduler_initializer_starts_background_jobs(monkeypatch):
|
||||
scheduler.init.assert_called_once_with()
|
||||
|
||||
|
||||
def test_meta_cache_expire_does_not_control_cache_clear_interval(monkeypatch):
|
||||
"""缓存清理任务应使用固定间隔,不受 META_CACHE_EXPIRE 控制。"""
|
||||
def test_clear_cache_is_manual_only(monkeypatch):
|
||||
"""缓存清理任务应仅手动执行,不注册到调度器自动运行。"""
|
||||
background_scheduler = _BackgroundSchedulerStub()
|
||||
generic_chain = Mock()
|
||||
for name in [
|
||||
@@ -98,11 +98,8 @@ def test_meta_cache_expire_does_not_control_cache_clear_interval(monkeypatch):
|
||||
scheduler.init()
|
||||
|
||||
scheduled_job_ids = {job["id"] for job in background_scheduler.jobs}
|
||||
assert "clear_cache" in scheduled_job_ids
|
||||
assert "clear_cache" not in scheduled_job_ids
|
||||
assert "clear_cache" in scheduler._jobs
|
||||
# 缓存清理使用固定 24 小时间隔,不受 META_CACHE_EXPIRE 控制
|
||||
clear_cache_job = next(
|
||||
job for job in background_scheduler.jobs if job["id"] == "clear_cache"
|
||||
)
|
||||
assert clear_cache_job["hours"] == 24
|
||||
assert scheduler._jobs["clear_cache"]["manual"] is True
|
||||
assert scheduler._jobs["clear_cache"]["provider_name"] == "[系统]"
|
||||
assert background_scheduler.started is True
|
||||
|
||||
Reference in New Issue
Block a user