• Stars
    star
    202
  • Rank 193,691 (Top 4 %)
  • Language
    Python
  • License
    Other
  • Created almost 12 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lightweight task scheduler using cron expressions

crython

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

Build Status 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 [email protected]: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()
        crython.join()  ## This will block

Stop the global job scheduler:

    crython.stop()
    crython.join(timeout=5000)  ## This will block 5s waiting for thread to stop.

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.

More Repositories

1

ulid

Universally Unique Lexicographically Sortable Identifier (ULID) in Python 3
Python
685
star
2

machine-learning-coursera

Machine Learning (Spring 2014)
MATLAB
63
star
3

django-ulid

Universally Unique Lexicographically Sortable Identifier (ULID) support in Django
Python
41
star
4

data-analysis-coursera

Computing for Data Analysis (Winter 2013)
R
35
star
5

scratchdir

Context manager to maintain your temporary directories/files.
Python
17
star
6

decorstate

Simple "state machines" with Python decorators.
Python
12
star
7

SaaS-Coursera

Assignments for UC Berkeley Spring 2012 SaaS Course
Ruby
7
star
8

adbpy

Deprecated. See: https://github.com/adbpy
Python
6
star
9

kettle

Python asyncio Kademlia Distributed Hash Table (DHT)
Python
6
star
10

KNN

K-Nearest Neighbors with Forward Feature Selection
4
star
11

NPortAudio

PortAudio wrapper for the .NET Framework
4
star
12

NLibsndfile

Libsndfile wrapper for the .NET Framework
C#
4
star
13

krustofsky

Convert social security popular baby names dataset to SQLite
Python
3
star
14

pysfeed

Live sports feeds as RESTful web service.
1
star
15

tcapy

Python bindings for JetBrains TeamCity REST API.
Python
1
star
16

eCostBot

eCost Auto-Buyer for Hot Deals
1
star
17

CS253-Udacity

1
star
18

ydf

YAML to Dockerfile
Python
1
star
19

tmnt

Mutation testing in python
Python
1
star
20

intellij-settings-pycharm

Repository for PyCharm IDE settings
1
star
21

NMU-Programming-Contests

1
star
22

python-challenge

http://www.pythonchallenge.com
Python
1
star
23

lopper

Automatically delete merged pull request branches for your GitHub Organization.
Python
1
star
24

etf

Erlang External Term Format support in Python.
Python
1
star
25

LovejoyBot

AIM service for NMU TLC students.
1
star
26

jpool

NFL pickem system built on ember.js and flask.
Python
1
star
27

ahawker

1
star
28

Powdered-Toast

Push notification system for .NET applications.
C#
1
star
29

euchre

Python
1
star