简体   繁体   中英

How can I schedule a task in determinated hours?

I want to run a task in week days, every 10 minutes between 8am and 17pm. I'm trying like this:

cron = BackgroundScheduler(daemon=True, timezone='UTC')
cron.add_job(service.test, trigger='cron',
             day_of_week='mon-fri', hour='7-16', minute=10)
cron.start()

but nothing happens. What am I doing wrong?

So, after a lot of research I found out that the problem wasn't the timezone, but me that didn't understood the code.

this:

cron = BackgroundScheduler(daemon=True, timezone=get_localzone())
cron.add_job(service.test, 'cron', day_of_week=(
    'mon-fri'), hour='7-16', minute=10)

means that at the 10th minute of every hour of every week day my code would be called, and not that it's going to be called every 10 minutes. Here's the docs of Cron-style scheduling, if someone wants to read more about https://apscheduler.readthedocs.io/en/v2.1.2/cronschedule.html . Thanks everybody for helping!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM