是否可以将 apscheduler cron 作业设置为以 90 秒的间隔运行?(我有 40 台机器,我想在一个小时内均匀地安排它们,而不将时间信息硬编码到脚本中)。我尝试过各种这样的:
job = sched.add_cron_job(_test, minute='*/1', second='30')
job = sched.add_cron_job(_test, minute='*', second='90')
是否可以将 apscheduler cron 作业设置为以 90 秒的间隔运行?(我有 40 台机器,我想在一个小时内均匀地安排它们,而不将时间信息硬编码到脚本中)。我尝试过各种这样的:
job = sched.add_cron_job(_test, minute='*/1', second='30')
job = sched.add_cron_job(_test, minute='*', second='90')
试试这个:
job = sched.add_interval_job(_test, seconds=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()
区间代码示例:
sched = BlockingScheduler()
sched.add_job(ClassTest, 'interval', seconds=90)
sched.start()