Python Apscheduler - 动态安排作业(嵌套)

Python Apscheduler - Schedule Jobs dynamically (nested)

我们需要在当前作业执行时动态安排多个作业。

大概的场景是:

所以我的代码是:

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 专为高效处理大量预定作业而设计,因此我相信您的预期使用方式是有效的。