AP调度程序。使用任何非内存存储关闭调度程序的最佳做法是什么?

APScheduler. What is the best practices to shutdown schedulers with any non memory storage?

我需要 运行 调度程序分布到多台机器上,并有一个单点来存储作业。为此,我使用了 Redis,我的代码如下所示:

jobstores = {'default': {'type': 'redis'}}
scheduler = BlockingScheduler(jobstores=jobstores)
scheduler.add_job(...)

当我将作业放入调度程序并调用 .start() 时,它会在 redis 中添加作业。但是当我 运行 我的调度程序的另一个实例或者当我停止当前的实例并重新 运行 它时,调度程序会在 redis 中添加更多作业(不进行清理)。

所以我有这个问题。做这些事情的最佳做法是什么?

提前致谢。

在为这种用法添加新作业时,您必须使用 replace_existing=True 选项。

来自documentation

If you schedule jobs in a persistent job store during your application’s initialization, you MUST define an explicit ID for the job and use replace_existing=True or you will get a new copy of the job every time your application restarts!