我正在尝试使用Advace Python Scheduler以编程方式调度一些作业,我的问题是在文档中只提到了如何使用'interval‘触发器类型来调度,那么'cron’和'date‘又如何呢?是否有关于APScheduler调度选项的完整文档?
例如:
#!/usr/bin/env python
from time import sleep
from apscheduler.scheduler import Scheduler
sched = Scheduler()
sched.start()
# define the function that is to be executed
def my_job(text):
print text
job = sched.add_job(my_job, 'interval', id='my_job', seconds=10, replace_existing=True, args=['job executed!!!!'])
while True:
sleep(1)如何根据“date”或“cron”安排日程
我使用的是最新的APScheduler版本3.0.2
谢谢
发布于 2015-04-03 18:19:02
sched.add_job(my_job, trigger='cron', hour='22', minute='30')表示每天22:30调用一次函数'my_job‘。
APScheduler是一个很好的东西,但缺少文档,这是一个遗憾,你可以阅读源代码来了解更多。
这里有更多的小贴士给你:
sched.add_job(my_job,trigger='cron',second='*') #每秒触发一次。
{‘年’:'*',‘月’:1,‘日’:1,‘周’:'*',‘日_周’:'*',‘小时’:0,‘分钟’:0,‘秒’:0}
在我看来,在大多数情况下,cron job可以替代date job。
发布于 2015-04-03 18:13:40
基于date
job = sched.add_date_job(my_job, '2013-08-05 23:47:05', ['text']) # or can pass datetime object.例如
import datetime
from datetime import timedelta
>>>job = sched.add_date_job(my_job, datetime.datetime.now()+timedelta(seconds=10), ['text'])
'text' # after 10 seconds基于cron
>>>job = sched.add_cron_job(my_job, second='*/5',args=['text'])
'text' every 5 seconds另一个例子
>>>job = sched.add_cron_job(my_job,day_of_week='mon-fri', hour=17,args=['text'])
"text" #This job is run every weekday at 5pmhttps://stackoverflow.com/questions/29429208
复制相似问题