1

是否可以将 apscheduler cron 作业设置为以 90 秒的间隔运行?(我有 40 台机器,我想在一个小时内均匀地安排它们,而不将时间信息硬编码到脚本中)。我尝试过各种这样的:

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

4

3 回答 3

5

试试这个:

job = sched.add_interval_job(_test, seconds=90)
于 2014-11-25T08:29:27.580 回答
1

根据您的问题,您希望在特定时间启动一项 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()

于 2019-12-02T16:38:02.340 回答
0

区间代码示例:

sched = BlockingScheduler()
sched.add_job(ClassTest, 'interval', seconds=90)
sched.start()
于 2015-03-28T08:03:15.203 回答