From 71ac12ab7a83e6e7f25803015b8fc5751c828484 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Wed, 28 Feb 2024 23:03:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20scheduler.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scheduler.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/scheduler.py b/app/scheduler.py index 4072193f..8b1afe84 100644 --- a/app/scheduler.py +++ b/app/scheduler.py @@ -258,21 +258,19 @@ class Scheduler(metaclass=Singleton): logger.warning(f"定时任务 {job_id} 正在运行 ...") return self._jobs[job_id]["running"] = True + # 开始运行 try: if not kwargs: kwargs = job.get("kwargs") or {} job["func"](*args, **kwargs) except Exception as e: logger.error(f"定时任务 {job_id} 执行失败:{str(e)}") - # 如果在job["func"]()运行时, 编辑配置导致任务被移除时, 该id已经不存在, 忽略错误 + # 运行结束 with self._lock: try: self._jobs[job_id]["running"] = False except KeyError: pass - # 如果是单次任务, 应立即移除缓存 - if not self._scheduler.get_job(job_id): - self._jobs.pop(job_id, None) def update_plugin_job(self, pid: str): """