GithubHelp home page GithubHelp logo

katyak20 / django-cron Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tivix/django-cron

0.0 1.0 0.0 432 KB

Write cron business logic as a Python class and let this app do the rest!

License: MIT License

django-cron's Introduction

django-cron

Django-cron lets you run Django/Python code on a recurring basis proving basic plumbing to track and execute tasks. The 2 most common ways in which most people go about this is either writing custom python scripts or a management command per cron (leads to too many management commands!). Along with that some mechanism to track success, failure etc. is also usually necesary.

This app solves both issues to a reasonable extent. This is by no means a replacement for queues like Celery ( http://celeryproject.org/ ) etc.

Installation

  • Install django_cron (ideally in your virtualenv!) using pip or simply getting a copy of the code and putting it in a directory in your codebase.

  • Add django_cron to your Django settings INSTALLED_APPS:

        INSTALLED_APPS = [
        # ...
        "django_cron",
    ]
    
  • If you're using South for schema migrations run python manage.py migrate django_cron or simply do a syncdb.

  • Write a cron class somewhere in your code, that extends the CronJobBase class. This class will look something like this:

    from django_cron import CronJobBase, Schedule
    class MyCronJob(CronJobBase):
        RUN_EVERY_MINS = 120 # every 2 hours
    
        schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
        code = 'my_app.my_cron_job' # a unique code
    
        def do(self):
                    pass    # do your thing here
    
  • Add a variable called CRON_CLASSES (similar to MIDDLEWARE_CLASSES etc.) thats a list of strings, each being a cron class. Eg.:

        CRON_CLASSES = [
        "my_app.cron.MyCronJob",
                # ...
    ]
    
  • Now everytime you run the management command python manage.py runcrons all the crons will run if required. Depending on the application the management command can be called from the Unix crontab as often as required. Every 5 minutes usually works for most of my applications.

This opensource app is brought to you by Tivix, Inc. ( http://tivix.com/ )

django-cron's People

Contributors

dfryta avatar raisins avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.