Python 列出apscheduler计划的cron作业
我使用脚本中的模块为每个月的最后一天安排作业。我正在CentOS机器上以Python 列出apscheduler计划的cron作业,python,python-2.7,cron,apscheduler,Python,Python 2.7,Cron,Apscheduler,我使用脚本中的模块为每个月的最后一天安排作业。我正在CentOS机器上以systemd脚本的形式运行此python脚本 from apscheduler.schedulers.blocking import BlockingScheduler if __name__ == '__main__': sched = BlockingScheduler() sched.add_job(lambda: my_aggregation_function(url_list, 'monthly
systemd
脚本的形式运行此python脚本
from apscheduler.schedulers.blocking import BlockingScheduler
if __name__ == '__main__':
sched = BlockingScheduler()
sched.add_job(lambda: my_aggregation_function(url_list, 'monthly'), 'cron', day='last')
while True:
sched.start()
我通过添加这些更改重新启动了脚本(systemd),脚本现在正在运行,作业已安排
我的问题是如何确认作业是否根据python脚本计划在配置时运行。我做了如下的cron列表,但找不到任何预定的列表
crontab -u root -l
对于交互式shell上的测试作业
# python
Python 2.7.5 (default, Nov 6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from apscheduler.schedulers.blocking import BlockingScheduler
>>> sched = BlockingScheduler()
>>> def job_function():
... print "Hello World"
...
>>> sched.add_job(job_function, 'cron', day='last')
<Job (id=c4b232a453dd4b5dbea5ef413d7a8c4d name=job_function)>
>>> sched.start()
我想这里有一个严重的误会。似乎您认为APScheduler以某种方式管理系统的cron作业。事实并非如此。它是一个进程内调度器,恰好有一个类似cron的触发器来调度作业。APScheduler与任何cron守护程序或crontab都没有任何连接 根据评论更新实际答案。API在官方文档中定义
scheduler.get_jobs()
感谢您的回答(我想是本模块的作者)。我确实确认了您的观点,即该模块不必与linux提供的实际
cron
守护进程做任何事情。但是,仅从apscheduler
透视图来看,不可能列出计划的作业吗?当然可以,使用啊!这么简单的一个!不确定我怎么会在文档中遗漏了这一点。
scheduler.get_jobs()