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.

PepperoniPizza
  • 8,842
  • 9
  • 58
  • 100

2 Answers2

16

Try this instead:

@sched.scheduled_job('interval', days=4, next_run_time=datetime.datetime.now())
Alex Grönholm
  • 5,563
  • 29
  • 32
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())
Yogesh Kate
  • 307
  • 3
  • 6