Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(desktop): 卸载被在跑的任务拦下时写出是哪个任务

longmeidaof42d6c8f081c
diff --git a/src/peach/routes_configuration.py b/src/peach/routes_configuration.py
index 80d64e573..b8e6bd8df 100644
--- a/src/peach/routes_configuration.py
+++ b/src/peach/routes_configuration.py
@@ -650,9 +650,12 @@ def uninstall(request: Request, body: dict = Body(...), _args=Depends(require_au
if body.get("confirmation") != "卸载 Peach":
raise HTTPException(400, "请确认卸载 Peach")
from .jobs import BackgroundJob
- if any(isinstance(job, BackgroundJob) and (job.snapshot() or {}).get("status") == "running"
- for job in vars(request.app.state.web_contract).values()):
- raise HTTPException(409, "后台任务正在运行,请完成后卸载")
+ from .task_runs import task_label
+ # 写出是哪几个:开机后自动跑的关注、订阅检查不在用户印象里,只说「后台任务」没处可找。
+ running = dict.fromkeys(task_label(job.task_key) for job in vars(request.app.state.web_contract).values()
+ if isinstance(job, BackgroundJob) and (job.snapshot() or {}).get("status") == "running")
+ if running:
+ raise HTTPException(409, f"{'、'.join(running)}正在运行,请在任务中心等它完成或取消后再卸载")
try:
return desktop_uninstall.request(settings_file.load_config(), body.get("delete_data"))
except (ValueError, Timeout) as exc:
diff --git a/tests/test_desktop_settings.py b/tests/test_desktop_settings.py
index 3a5e7ea70..f36afe58c 100644
--- a/tests/test_desktop_settings.py
+++ b/tests/test_desktop_settings.py
@@ -180,6 +180,14 @@ class DesktopSettingsTests(unittest.TestCase):
remove.assert_not_called()
self.assertEqual(client.post('/api/configuration/uninstall',json={'delete_data':False,'confirmation':'卸载 Peach'}).status_code,200)
remove.assert_called_once_with(self.config,False)
+ from peach.jobs import BackgroundJob
+ follow = BackgroundJob('PeachFollowCheckJob', task_key='follow-check')
+ follow.state = {'job_id': 'running-follow', 'status': 'running'}
+ app.state.web_contract = SimpleNamespace(follow_job=follow)
+ busy = client.post('/api/configuration/uninstall',json={'delete_data':False,'confirmation':'卸载 Peach'})
+ self.assertEqual(busy.status_code,409)
+ self.assertEqual(busy.json()['detail'],'追更检查正在运行,请在任务中心等它完成或取消后再卸载')
+ remove.assert_called_once()
self.assertEqual(client.post('/api/configuration/startup',json={'enabled':'false','silent':True}).status_code,400)
self.assertEqual(client.post('/api/configuration/peach-proxy',json={'mode':'proxy','proxy':'invalid'}).status_code,400)
# 外部入口:域名不成形时整批不写,落下去的会是一排点过去必然落空的入口。