mirror of
https://github.com/Cp0204/quark-auto-save.git
synced 2026-01-11 22:50:45 +08:00
🐛 补充修复:添加 APScheduler 调度器参数,彻底解决任务堆积问题 (#126)
This commit is contained in:
parent
956105c16e
commit
95ddc95c79
16
app/run.py
16
app/run.py
@ -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()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user