6

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?

thebjorn
  • 26,297
  • 11
  • 96
  • 138
  • Possible duplicate of http://stackoverflow.com/questions/1511854/parse-a-cron-entry-in-python – mjhm Nov 16 '10 at 03:45
  • It is a duplicate, but that question was never answered either... The obvious path here is to start with Python-crontab, and just enhance it to support what you're looking for (should be relatively simple gymnastics with the datetime module once you have the string parsed). – Nick Bastin Nov 16 '10 at 04:12

1 Answers1

3

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