我们需要在当前作业执行时动态调度多个作业。
大概的场景是:
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)
查询是:
最佳答案
APScheduler 3.0 专为高效处理大量预定作业而设计,因此我相信您使用它的预期方式是有效的。
关于Python Apscheduler - 动态调度作业(嵌套),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34218760/