apscheduler at 90 second intervals?

3.8k views Asked by At

Is it possible to set an apscheduler cron job to run at 90 second intervals? (I have 40 machines that I'd like to schedule evenly over an hour without hard coding time info into the script). I've tried various kinds of this:

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

3

There are 3 answers

3
Alex Grönholm On

Try this instead:

job = sched.add_interval_job(_test, seconds=90)
1
codewhiz On

Based on your question you want to start a cron job at a particular time and run it indefinitely with 90 seconds interval. You can achieve this by 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()

1
user3159821 On

Interval code example:

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