Lightweight task scheduler using cron expressions.
Project description
crython is a lightweight task (function) scheduler using cron expressions written in python.
Status
This module is actively maintained.
Installation
To install crython from pip:
$ pip install crython
To install crython from source:
$ git clone git@github.com:ahawker/crython.git
$ python setup.py install
Usage
Crython supports seven fields (seconds, minutes, hours, day of month, month, weekday, year).
Call a function once a minute:
import crython
# Fire once a minute.
@crython.job(second=0)
def foo():
print "... while heavy sack beatings are up a shocking nine hundred percent? - Kent Brockman"
Call a function every ten seconds:
# Fire every 10 seconds.
@crython.job(second=range(0, 60, 10))
def foo():
print "I'm a big four-eyed lame-o and I wear the same stupid sweater every day. - Homer's Brain"
Call a function with a single cron expression:
# Fire every 10 seconds.
@crython.job(second='*/10')
def foo():
print "Hail to the thee Kamp Krusty... - Kampers"
Call a function with a full cron expression:
# Fire once a week.
@crython.job(expr='0 0 0 * * 0 *')
def foo():
print "Back in line, maggot! - Kearny"
Call a function with positional and/or keyword arguments:
# Fire every second.
@job('safety gloves', second='*', name='Homer Simpson')
def foo(item, name):
print "Well, I don't need {0}, because I'm {1}. -- Grimey".format(item, name)
Call a function using predefined keywords:
# Fire once a day.
@crython.job(expr='@daily')
def foo():
print "That's where I saw the leprechaun. He tells me to burn things! - Ralph Wiggum"
# Fire once immediately after scheduler starts.
@crython.job(expr='@reboot')
def foo():
print "I call the big one bitey. - Homer Simpson"
Call a function and run it within a separate thread (default behaviour if ctx is not specified):
# Fire once a week.
@crython.job(expr='@weekly', ctx='thread')
def foo():
print "No, no, dig up stupid. - Chief Wiggum"
Call a function and run it within a separate process:
# Fire every hour.
@crython.job(expr='@hourly', ctx='multiprocess')
def foo():
print "Eat my shorts. - Bart Simpson"
Start the global job scheduler:
if __name__ == '__main__':
crython.start()
Keywords
Entry |
Description |
Equivalent To |
---|---|---|
@yearly/@annually |
Run once a year at midnight in the morning of January 1 |
0 0 0 0 1 1 * |
@monthly |
Run once a month at midnight in the morning of the first of the month |
0 0 0 0 1 * * |
@weekly |
Run once a week at midnight in the morning of Sunday |
0 0 0 0 * 0 * |
@daily |
Run once a day at midnight |
0 0 0 * * * * |
@hourly |
Run once an hour at the beginning of the hour |
0 0 * * * * * |
@minutely |
Run once a minute at the beginning of the minute |
0 * * * * * * |
@reboot |
Run once at startup |
@reboot |
TODO
Support “L”, “W” and “#” specials.
Determine time delta from now -> next time expression is valid.
Contributing
If you would like to contribute, simply fork the repository, push your changes and send a pull request.
License
Crython is available under the MIT license.
See Other
There are similar python cron libraries out there. See: pycron, python-crontab, cronex.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file crython-0.2.0.tar.gz
.
File metadata
- Download URL: crython-0.2.0.tar.gz
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.4.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27adb886ad3f87aaa257c8b947a5578eea05df619dff8bbabdced680971313ce |
|
MD5 | 6ad6638f95995dc2106cdf0b1317901b |
|
BLAKE2b-256 | 6dd3ca918cb4b77e219784a23cdf81a88ed2265964a30e6d89023153665bdb0f |
File details
Details for the file crython-0.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: crython-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.4.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 002e74a0895411571fd4e9ce89f8f674daaeff7072f05dfd5d97cfa6d91a7aa3 |
|
MD5 | 65815704295d9018545b391ff3eacfbf |
|
BLAKE2b-256 | a453a2459e4e55c285706465d2a003c7205a5c91f53990dd7c28bc5ed71ec04a |