【发布时间】:2018-08-11 01:08:26
【问题描述】:
我正在开发一个使用 BackgroundScheduler 的 Flask 应用程序。该应用程序的一项功能是发送在特定日期安排工作的请求,但前提是该日期还没有工作。所以我想我可以依靠工作id 参数是唯一的......但是,看起来它不一定是。
这是一个超级简单的示例,将两个具有相同id 的作业添加到调度程序:
from apscheduler.schedulers.background import BackgroundScheduler
scheduler = BackgroundScheduler()
def hello():
print "Hello!"
def goodbye():
print "Goodbye!"
scheduler.add_job(hello, trigger='interval', seconds=5, id='1')
scheduler.add_job(goodbye, trigger='interval', seconds=5, id='1')
print scheduler.get_jobs()
print scheduler.get_job('1')
哪个输出
[<Job (id=1 name=hello)>, <Job (id=1 name=goodbye)>]
hello (trigger: interval[0:00:05], pending)
由于 ID 冲突,我预计这会出错。但是,这两个作业都已注册,并且在查询特定作业 ID 时,只返回第一个。
此外,将replace_existing 参数设置为True 似乎并不能取代这项工作。
我是否遗漏了一些重要的东西,比如配置作业商店?
【问题讨论】:
-
似乎是合法的问题!
标签: python apscheduler