Is there a Python module to get next runtime from a crontab-style time definition?

烂漫一生 提交于 2019-12-21 17:28:28

问题


I'm writing a dashboard application and I need a way to figure out how long an item is "valid", i.e. when should it have been superseded by a new value (it's possible to have an error such that the next value never arrives).

Since I know the schedules for the processes producing data, I can define valid as "until the next time the process should have ran".

I thought the crontab format for specifying schedules was very compact (i.e. easy to store in a database), and also easy to understand.

Finally the question: is there a Python module, that when given the current time and a crontab spec (e.g. "25 5 * * *"), returns a datetime giving the next runtime?


回答1:


I ran into some issues using the code (from http://www.koders.com/python/fidA55A9DB55093A78DD26B55C606B267B2C5063A79.aspx?s=config) , and have fixed some of them. It used to break going from one month to the next. next_run now works fine, but prev_run gets stuck going from one month the previous (instead of failing it gets caught in a loop)

Here is a git repository that I've set up to continue working on it:

https://github.com/RFDaemoniac/crontab_parser



来源:https://stackoverflow.com/questions/4190997/is-there-a-python-module-to-get-next-runtime-from-a-crontab-style-time-definitio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!