Lightweight task scheduler using cron expressions
Python Makefile
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
crython Drop support for py33. Apr 5, 2018
docs
requirements Update sphinx from 1.7.4 to 1.7.5 May 30, 2018
tests Rename the class method 'reboot' to 'from_reboot'. Oct 7, 2017
.bumpversion.cfg Bump version: 0.0.7 → 0.0.8 Aug 24, 2017
.codeclimate.yml Ignore docs build directory for codeclimate. Apr 9, 2017
.coveragerc Update .coveragerc with common excludes and branch coverage. Jan 4, 2017
.gitignore Update .gitignore from latest. Oct 7, 2017
.hound.yml Add hound config file. Oct 8, 2017
.pylintrc Add NOTE, OPTIMIZE, HACK, and BUG to pylint note checker. Oct 7, 2017
.pyup.yml Add pyup config file. Oct 7, 2017
.travis.yml Remove test pypi deployment. May 8, 2018
CHANGELOG.md Add CHANGELOG.md. Oct 8, 2017
LICENSE.md LICENSE is in markdown not plaintext. Updated README examples and add… Feb 22, 2013
MANIFEST.in Added tox.ini for testing and updated setup.py for the 'test' command. Feb 23, 2013
Makefile Remove 'codeclimate-install' make target. Oct 16, 2017
README.md Swap codeclimate coverage badge with codecov.io badge. Oct 16, 2017
README.rst Swap codeclimate coverage badge with codecov.io badge. Oct 16, 2017
pytest.ini Set pytest config to generate XML coverage report. Oct 16, 2017
setup.cfg Add [flake8] section to setup.cfg for Hound CI. Oct 18, 2017
setup.py Drop support for py33. Apr 5, 2018
tox.ini Add tox environment for running scan target. Oct 7, 2017

README.md

crython

Join the chat at https://gitter.im/crython/Lobby

Build Status codecov Code Climate Issue Count

PyPI version PyPI versions

Stories in Ready

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 process:

    # Fire every hour.
    @crython.job(expr='@hourly', ctx='process')
    def foo():
        print "No, no, dig up stupid. - Chief Wiggum"

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.