🐛 补充修复:添加 APScheduler 调度器参数,彻底解决任务堆积问题 (#126)

This commit is contained in:
ypq123456789 2025-10-14 13:31:02 +08:00 committed by GitHub
parent 956105c16e
commit 95ddc95c79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -495,11 +495,21 @@ def run_python(args):
logging.error(f">>> 任务执行失败,返回码: {result.returncode}")
if result.stderr:
logging.error(f"错误信息: {result.stderr[:500]}")
except subprocess.TimeoutExpired:
except subprocess.TimeoutExpired as e:
logging.error(f">>> 任务执行超时(超过 {timeout} 秒),已强制终止")
# 尝试终止进程
if e.process:
try:
e.process.kill()
logging.info(">>> 已终止超时进程")
except:
pass
except Exception as e:
logging.error(f">>> 任务执行异常: {str(e)}")
logging.error(traceback.format_exc())
finally:
# 确保函数能够正常返回
logging.debug(f">>> run_python 函数执行完成")
# 重新加载任务
@ -515,6 +525,10 @@ def reload_tasks():
trigger=trigger,
args=[f"{SCRIPT_PATH} {CONFIG_PATH}"],
id=SCRIPT_PATH,
max_instances=1, # 最多允许1个实例运行
coalesce=True, # 合并错过的任务,避免堆积
misfire_grace_time=300, # 错过任务的宽限期(秒),超过则跳过
replace_existing=True, # 替换已存在的同ID任务
)
if scheduler.state == 0:
scheduler.start()