Skip to content
Advertisement

How can I run task every 10 minutes on the 5s, using BlockingScheduler?

I’m trying to run a task every 10 minutes, on the 5’s, for example, at 13:15, 13:25, ….

However, it is not working.

This is only running once an hour, at the beginning of the hour, from 12 to 4pm.

sched.add_job(run_batch, 'cron', day_of_week='mon-fri', hour='12-16', minute='5,15,25,35,45,55', timezone='America/Chicago')

Advertisement

Answer

The question title indicates that you are using the BlockingScheduler function of the Python library — Advanced Python Scheduler (APScheduler).

Based on your question, you want to run a cron job within a Python script Monday through Friday between 1200 and 1600. You want the job to run at 12:05, 12:15, 12:25, etc.

I have not fully tested the answer below, but I did run the test for 1 hour (starting at 8am today) and it fired correctly at 8:05, 8:15, 8:25, 8:35, 8:45, 8:55 and 9:05.

I used the start_date variable to start the scheduler at a precise date and time.

JavaScript

BTW You can replace these time intervals.

JavaScript

with this, which I tested.

JavaScript

Just a side question. Have you considered using UTC over Central Time?

JavaScript

Please let me know if you have any issues with this code and I will look into them for you.

Advertisement