Sequentially Run Pending Tasks With Python Aps
Suppose I have two cron triggers: trigger1 = CronTrigger(second='0,20,40') trigger2 = CronTrigger(second='0,10,20,30,40,50') and I create my scheduler like this: scheduler = Bloc
Solution 1:
Use DebugExecutor. For example:
from apscheduler.schedulers.blocking import BlockingScheduler
from apscheduler.executors.debug import DebugExecutor
def foo1():
print("x")
def foo2():
time.sleep(3)
print("y")
scheduler = BlockingScheduler()
scheduler.add_executor(DebugExecutor(), "consecutive")
scheduler.add_job(foo1, 'interval', max_instances=1, seconds=1, executor="consecutive")
scheduler.add_job(foo2, 'interval', max_instances=1, seconds=5, executor="consecutive")
Solution 2:
Use DebugExecutor
is a good idea, additionally I needed to specify a high value for the misfire_grace_time parameter in .add_job()
to avoid skipping runs when multiple jobs have same execution interval
Post a Comment for "Sequentially Run Pending Tasks With Python Aps"