我们要求在当前作业执行时动态调度多个作业。
近似情景是:
resume_dttime
resume_dttime
所以我的代码是:
from apscheduler.schedulers.blocking import BlockingScheduler
sched = BlockingScheduler()
@sched.scheduled_job('cron', day_of_week='mon-fri', hour=6)
def scheduled_job():
"""
"""
liveusers = todays_userslist() #Get users from table with todays resume_dttime
for u in liveusers:
user_job = get_userjob(u.id)
runtime = u.resume_dttime #eg u.resume_dttime is datetime(2015, 12, 13, 16, 30, 5)
sched.add_job(user_job, 'date', run_date=runtime, args=[u.name])
if __name__ == "__main__":
sched.start()
sched.shutdown(wait=True)
查询是:
答案 0 :(得分:2)
APScheduler 3.0专门设计用于高效处理大量预定作业,因此我相信您使用它的预期方式是有效的。