Search code examples
apscheduler

Run Job every 4 days but first run should happen now


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.


Solution

  • Try this instead:

    @sched.scheduled_job('interval', days=4, next_run_time=datetime.datetime.now())