Python Apscheduler conditional tasks

时间:2015-05-12 23:10:44

标签: python apscheduler

I have a simple set of functions _Static_assert and foo. I want to run the second job bar only after successful completion of the task/function bar.

Currently I am doing this with a global variable as such:

foo

Is there a better way to have conditional tasks with from apscheduler.scheduler import Scheduler success = 0 def foo(): global success try: print 'yes' except: success = 0 return success = 1 return def bar(): if success: print 'yes' else: print 'no' return scheduler = Scheduler() scheduler.add_cron_job(foo, day_of_week='mon-fri', hour=18, minute=30); scheduler.add_cron_job(bar, day_of_week='mon-fri', hour=18, minute=45) scheduler.start() ?

1 个答案:

答案 0 :(得分:1)

如果成功,则在foo()的15分钟内安排新的bar()运行。

像这样:

from datetime import datetime, timedelta

def foo():
    print 'yes'
    scheduler.add_date_job(bar, datetime.now() + timedelta(minutes=15))