Skip to main content

Lightweight task scheduler using cron expressions.

Project description

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

Entr y

Desc ript ion

Equi vale nt To

@yea rly/ @ann uall y

Run once a year at midn ight in the morn ing of Janu ary 1

0 0 0 0 1 1 *

@mon thly

Run once a mont h at midn ight in the morn ing of the firs t of the mont h

0 0 0 0 1 * *

@wee kly

Run once a week at midn ight in the morn ing of Sund ay

0 0 0 0 * 0 *

@dai ly

Run once a day at midn ight

0 0 0 * * * *

@hou rly

Run once an hour at the begi nnin g of the hour

0 0 * * * * *

@min utel y

Run once a minu te at the begi nnin g of the minu te

0 * * * * * *

@reb oot

Run once at star tup

@reb oot

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crython-0.0.9.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

crython-0.0.9-py2.py3-none-any.whl (15.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file crython-0.0.9.tar.gz.

File metadata

  • Download URL: crython-0.0.9.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.4.6

File hashes

Hashes for crython-0.0.9.tar.gz
Algorithm Hash digest
SHA256 11f94e94e9e700428dfdcdbe1efc2d179392bc983ca0e2940f60dc4a85f85ee8
MD5 51d81a0f3ca217982cea9599896272b3
BLAKE2b-256 b25e4d4b900d0cf89a3b07d90e2c4891b6788de7007fcc4c6b320fda12f99bda

See more details on using hashes here.

File details

Details for the file crython-0.0.9-py2.py3-none-any.whl.

File metadata

  • Download URL: crython-0.0.9-py2.py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.4.6

File hashes

Hashes for crython-0.0.9-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 98014aa9826d420bd21713408e978e6ab439fec5ee58a619f84be1a89b340dcb
MD5 5ad13313cb28d6929384d7f3828ed96d
BLAKE2b-256 5938055ada46eb9c852b7f1d76dd861d87f3e99c1761f8d6c921f22c6d515a7c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page