指定定时任务执行的时机
1.在特定时间执行:run_date
from datetime import date
sched.add_job(my_job, 'date', run_date=date(2009, 11, 6))
sched.add_job(my_job, 'date', run_date='2009-11-06')
sched.add_job(my_job, 'date')
sched.start()
2.间隔执行:interval
from datetime import datetime
sched.add_job(job_function, 'interval', hours=2)
sched.add_job(job_function, 'interval', hours=2, start_date='2010-10-10 09:30:00', end_date='2014-06-15 11:00:00')
参数 | 描述 |
---|
weeks (int) | number of weeks to wait |
days (int) | number of days to wait |
hours (int) | number of hours to wait |
minutes (int) | number of minutes to wait |
seconds (int) | number of seconds to wait |
start_date (datetime | str) |
end_date (datetime | str) |
timezone (datetime.tzinfo | str) |
3.周期执行:cron
sched.add_job(job_function, 'cron', month='6-8,11-12', day='3rd fri', hour='0-3')
sched.add_job(job_function, 'cron', day_of_week='mon-fri', hour=5, minute=30, end_date='2014-05-30')
参数 | 描述 |
---|
year (int | str) |
month (int | str) |
day (int | str) |
week (int | str) |
day_of_week (int | str) |
hour (int | str) |
minute (int | str) |
second (int | str) |
start_date (datetime | str) |
end_date (datetime | str) |
timezone (datetime.tzinfo | str) |