Run Job every 4 days but first run should happen now
Asked Answered
A

2

7

I am trying to setup APScheduler to run every 4 days, but I need the job to start running now. I tried using interval trigger but I discovered it waits the specified period before running. Also I tried using cron the following way:

sched = BlockingScheduler()
sched.add_executor('processpool')

@sched.scheduled_job('cron', day='*/4')
def test():
    print('running')

One final idea I got was using a start_date in the past:

@sched.scheduled_job('interval', seconds=10, start_date=datetime.datetime.now() - datetime.timedelta(hours=4))

but that still waits 10 seconds before running.

Ammoniate answered 28/1, 2018 at 13:39 Comment(0)
S
18

Try this instead:

@sched.scheduled_job('interval', days=4, next_run_time=datetime.datetime.now())
Silvester answered 29/1, 2018 at 5:13 Comment(1)
it doesn't work, it skips it by a few milliseconds.Paramedical
V
2

Similar to the above answer, only difference being it uses add_job method.

scheduler = BlockingScheduler()
scheduler.add_job(dump_data, trigger='interval', days=21,next_run_time=datetime.datetime.now())
Valera answered 5/9, 2019 at 4:30 Comment(2)
it doesn't work, it skips it by a few milliseconds.Paramedical
What do you mean by skipping it by a few milliseconds? APScheduler (3.x) has a precision of one second.Geminian

© 2022 - 2025 — McMap. All rights reserved.