License | Version | ||
Github Actions | Coverage | ||
Supported versions | Wheel | ||
Status | Downloads |
Schedule with Docstrings
pip install DocCron
Cron-based scheduler inspired by doctest
Cron jobs can be embedded into docstrings by using a literal block (::
). Literal blocks should start with /etc/crontab
.
Run hello()
at every 2nd minute and 3rd minute:
import time
def hello():
"""
Print "hello world" at every 2nd minute and 3rd minute:
/etc/crontab::
*/2 * * * *
*/3 * * * *
"""
print(time.strftime('%Y-%m-%d %H:%M:%S'), "hello world")
if __name__ == '__main__':
import doccron
doccron.run_jobs()
Run hello()
at every 2nd second and 3rd second:
import time
def hello():
"""
Print "hello world" every 2nd second and 3rd second:
/etc/crontab::
*/2 * * * * *
*/3 * * * * *
"""
print(time.strftime('%Y-%m-%d %H:%M:%S'), "hello world")
if __name__ == '__main__':
import doccron
doccron.run_jobs(quartz=True)
DocCron now support CRON_TZ
. The value of CRON_TZ
only applies to succeeding cron jobs.
DocCron supports multiple CRON_TZ
in a cron table. The default timezone value is the local/system timezone, if not specified.
import time
def hello():
"""
Print "hello world" at every 2nd minute and 3rd minute:
/etc/crontab::
CRON_TZ=UTC
*/2 * * * *
*/3 * * * *
"""
print(time.strftime('%Y-%m-%d %H:%M:%S%z'), "hello world")
if __name__ == '__main__':
import doccron
doccron.run_jobs()
- Standard and extended cron formats (see CRON Expression)
- Nonstandard predefined scheduling definitions
- Non-standard characters
- Quartz format
- Works with documentation tools like Sphinx
- Timezone-awareness (CRON_TZ)
- Interval (e.g.,
@every 1h2m3s
)
- Human-readable date/time strings