apscheduler每隔90秒?

时间:2014-11-24 17:26:46

标签: apscheduler

是否可以将apscheduler cron作业设置为以90秒的间隔运行? (我有40台机器,我希望在一小时内均匀安排,而无需在脚本中编写时间信息。)我尝试了各种各样的方法:



job = sched.add_cron_job(_test, minute='*/1', second='30')
job = sched.add_cron_job(_test, minute='*', second='90')




3 个答案:

答案 0 :(得分:3)

请改为尝试:

job = sched.add_interval_job(_test, seconds=90)

答案 1 :(得分:0)

区间代码示例:

sched = BlockingScheduler()
sched.add_job(ClassTest, 'interval', seconds=90)
sched.start()

答案 2 :(得分:0)

根据您的问题,您想在特定时间启动cron作业,并以90秒的间隔无限期地运行它。您可以通过combining triggers

来实现
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.combining import AndTrigger
from apscheduler.triggers.interval import IntervalTrigger
from apscheduler.triggers.cron import CronTrigger


def _test():
    print("code comes here")


scheduler = BackgroundScheduler()

#  Runs on 2019-12-30 at 5:30 (am) & repeats every 90 seconds interval
trigger = AndTrigger([IntervalTrigger(seconds=90),
                      CronTrigger(start_date='2019-12-30', hour=5, minute=30)])

scheduler.add_job(_test, trigger)
scheduler.start()