django-crontab


Namedjango-crontab JSON
Version 0.7.1 PyPI version JSON
download
home_pagehttps://github.com/kraiz/django-crontab
Summarydead simple crontab powered job scheduling for django
upload_time2016-03-07 19:35:54
maintainerNone
docs_urlNone
authorLars Kreisz
requires_pythonNone
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            .. image:: https://img.shields.io/travis/kraiz/django-crontab/master.svg
    :target: https://travis-ci.org/kraiz/django-crontab
.. image:: https://img.shields.io/coveralls/kraiz/django-crontab/master.svg
    :target: https://coveralls.io/r/kraiz/django-crontab
.. image:: https://img.shields.io/pypi/dw/django-crontab.svg
    :target: https://pypi.python.org/pypi/django-crontab
.. image:: https://img.shields.io/pypi/v/django-crontab.svg
    :target: https://pypi.python.org/pypi/django-crontab
.. image:: https://img.shields.io/pypi/pyversions/django-crontab.svg
    :target: https://pypi.python.org/pypi/django-crontab
.. image:: https://img.shields.io/pypi/l/django-crontab.svg
    :target: https://pypi.python.org/pypi/django-crontab

about
=====

dead simple crontab powered job scheduling for django (1.8+).

setup
=====
install via pip::

    pip install django-crontab

add it to installed apps in django settings.py::

    INSTALLED_APPS = (
        'django_crontab',
        ...
    )

now create a new method that should be executed by cron every 5 minutes, f.e. in `myapp/cron.py`::

    def my_scheduled_job():
      pass

now add this to your settings.py::

    CRONJOBS = [
        ('*/5 * * * *', 'myapp.cron.my_scheduled_job')
    ]

you can also define positional and keyword arguments which let you call django management commands::

    CRONJOBS = [
        ('*/5 * * * *', 'myapp.cron.other_scheduled_job', ['arg1', 'arg2'], {'verbose': 0}),
        ('0   4 * * *', 'django.core.management.call_command', ['clearsessions']),
    ]

finally run this command to add all defined jobs from `CRONJOBS` to crontab (of the user which you are running this command with)::

    python manage.py crontab add

show current active jobs of this project::

    python manage.py crontab show

removing all defined jobs is straight forward::

    python manage.py crontab remove

config
======
there are a bunch of setting vars to customize behavior. each of this comes with default values that should properly fit. if not, feel free to overwrite.

CRONJOBS
  - list of jobs, each defined as tuple:

    - format 1:

      1. required: cron timing (in usual format: http://en.wikipedia.org/wiki/Cron#Format)
      2. required: the python module path to the method
      3. optional: a job specific suffix (f.e. to redirect out/err to a file, default: '')

    - format 2:

      1. required: cron timing (in usual format: http://en.wikipedia.org/wiki/Cron#Format)
      2. required: the python module path to the method
      3. optional: list of positional arguments for the method (default: [])
      4. optional: dict of keyword arguments for the method (default: {})
      5. optional: a job specific suffix (f.e. to redirect out/err to a file, default: '')

  - NOTE: Run "python manage.py crontab add" each time you change CRONJOBS in any way!
  - default: []
  - example::

        CRONJOBS = [
            ('*/5 * * * *', 'myapp.cron.my_scheduled_job'),

            # format 1
            ('0   0 1 * *', 'myapp.cron.my_scheduled_job', '>> /tmp/scheduled_job.log'),

            # format 2
            ('0   0 1 * *', 'myapp.cron.other_scheduled_job', ['myapp']),
            ('0   0 * * 0', 'django.core.management.call_command', ['dumpdata', 'auth'], {'indent': 4}, '> /home/john/backups/last_sunday_auth_backup.json'),
        ]

CRONTAB_LOCK_JOBS
  - prevent starting a job if an old instance of the same job is still running
  - default: False
  - since 0.5.0

CRONTAB_EXECUTABLE
  - path to the crontab executable of your os
  - default: '/usr/bin/crontab'

CRONTAB_DJANGO_PROJECT_NAME
  - the name of your django project, used to build path path to manage.py and to mark the jobs in contrab via comment for later removing
  - default is read from DJANGO_SETTINGS_MODULE environment variable

CRONTAB_DJANGO_MANAGE_PATH
  - path to manage.py file (including the manage.py itself, i.e. '/home/john/web/manage.py')
  - default is build using DJANGO_PROJECT_NAME

CRONTAB_DJANGO_SETTINGS_MODULE
  - dotted python path to the settings module to run the command with
  - default is the common one from the environment variable and will not be overwritten
  - since 0.6.0

CRONTAB_PYTHON_EXECUTABLE
  - path to the python interpreter executable used to run the scheduled job
  - default uses the interpreter executable used to `add` the jobs (via 'python manage.py crontab add')

CRONTAB_COMMAND_PREFIX
  - something you wanne do or declare before each job gets executed. A good point for environment variables.
  - default: '' (empty string)
  - example: 'STAGE=production'

CRONTAB_COMMAND_SUFFIX
  - something you wanne do after each job was executed.
  - default: '' (empty string)
  - example: '2>&1'

CRONTAB_COMMENT
  - used for marking the added contab-lines for removing, default value includes project name to distinguish multiple projects on the same host and user
  - default: 'django-crontabs for ' + CRONTAB_DJANGO_PROJECT_NAME

contributors
============
arski cinghiale meric426 justdoit0823 chamaken

faq
===
* **I'm using this old django version (<1.8) and can't install this package. What should i do?**
  - Yeah, update django of course (!) or - as you seem to be familiar with old, unsupported versions, install the old version of this package too (it support django 1.3-1.7)::

    pip install django-crontab==0.6.0

* **Will it work with windows?**
  - No.
* **I'm getting "bad command"/"errors in cronfile" while installing via "crontab add". What's wrong?**
  - Maybe it's your cron time format, it can have 5 or 6 fields. Check that your system supports 6 or just define 5 in `CRONJOBS`. (see #23)

license
=======
MIT-License, see LICENSE file.
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/kraiz/django-crontab",
    "name": "django-crontab",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Lars Kreisz",
    "author_email": "lars.kreisz@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/37/bd/a122ba96167f5dfab70a58ca22fa046b7ef1ebad9ff026f7831bd6c2a49c/django-crontab-0.7.1.tar.gz",
    "platform": "UNKNOWN",
    "description": ".. image:: https://img.shields.io/travis/kraiz/django-crontab/master.svg\n    :target: https://travis-ci.org/kraiz/django-crontab\n.. image:: https://img.shields.io/coveralls/kraiz/django-crontab/master.svg\n    :target: https://coveralls.io/r/kraiz/django-crontab\n.. image:: https://img.shields.io/pypi/dw/django-crontab.svg\n    :target: https://pypi.python.org/pypi/django-crontab\n.. image:: https://img.shields.io/pypi/v/django-crontab.svg\n    :target: https://pypi.python.org/pypi/django-crontab\n.. image:: https://img.shields.io/pypi/pyversions/django-crontab.svg\n    :target: https://pypi.python.org/pypi/django-crontab\n.. image:: https://img.shields.io/pypi/l/django-crontab.svg\n    :target: https://pypi.python.org/pypi/django-crontab\n\nabout\n=====\n\ndead simple crontab powered job scheduling for django (1.8+).\n\nsetup\n=====\ninstall via pip::\n\n    pip install django-crontab\n\nadd it to installed apps in django settings.py::\n\n    INSTALLED_APPS = (\n        'django_crontab',\n        ...\n    )\n\nnow create a new method that should be executed by cron every 5 minutes, f.e. in `myapp/cron.py`::\n\n    def my_scheduled_job():\n      pass\n\nnow add this to your settings.py::\n\n    CRONJOBS = [\n        ('*/5 * * * *', 'myapp.cron.my_scheduled_job')\n    ]\n\nyou can also define positional and keyword arguments which let you call django management commands::\n\n    CRONJOBS = [\n        ('*/5 * * * *', 'myapp.cron.other_scheduled_job', ['arg1', 'arg2'], {'verbose': 0}),\n        ('0   4 * * *', 'django.core.management.call_command', ['clearsessions']),\n    ]\n\nfinally run this command to add all defined jobs from `CRONJOBS` to crontab (of the user which you are running this command with)::\n\n    python manage.py crontab add\n\nshow current active jobs of this project::\n\n    python manage.py crontab show\n\nremoving all defined jobs is straight forward::\n\n    python manage.py crontab remove\n\nconfig\n======\nthere are a bunch of setting vars to customize behavior. each of this comes with default values that should properly fit. if not, feel free to overwrite.\n\nCRONJOBS\n  - list of jobs, each defined as tuple:\n\n    - format 1:\n\n      1. required: cron timing (in usual format: http://en.wikipedia.org/wiki/Cron#Format)\n      2. required: the python module path to the method\n      3. optional: a job specific suffix (f.e. to redirect out/err to a file, default: '')\n\n    - format 2:\n\n      1. required: cron timing (in usual format: http://en.wikipedia.org/wiki/Cron#Format)\n      2. required: the python module path to the method\n      3. optional: list of positional arguments for the method (default: [])\n      4. optional: dict of keyword arguments for the method (default: {})\n      5. optional: a job specific suffix (f.e. to redirect out/err to a file, default: '')\n\n  - NOTE: Run \"python manage.py crontab add\" each time you change CRONJOBS in any way!\n  - default: []\n  - example::\n\n        CRONJOBS = [\n            ('*/5 * * * *', 'myapp.cron.my_scheduled_job'),\n\n            # format 1\n            ('0   0 1 * *', 'myapp.cron.my_scheduled_job', '>> /tmp/scheduled_job.log'),\n\n            # format 2\n            ('0   0 1 * *', 'myapp.cron.other_scheduled_job', ['myapp']),\n            ('0   0 * * 0', 'django.core.management.call_command', ['dumpdata', 'auth'], {'indent': 4}, '> /home/john/backups/last_sunday_auth_backup.json'),\n        ]\n\nCRONTAB_LOCK_JOBS\n  - prevent starting a job if an old instance of the same job is still running\n  - default: False\n  - since 0.5.0\n\nCRONTAB_EXECUTABLE\n  - path to the crontab executable of your os\n  - default: '/usr/bin/crontab'\n\nCRONTAB_DJANGO_PROJECT_NAME\n  - the name of your django project, used to build path path to manage.py and to mark the jobs in contrab via comment for later removing\n  - default is read from DJANGO_SETTINGS_MODULE environment variable\n\nCRONTAB_DJANGO_MANAGE_PATH\n  - path to manage.py file (including the manage.py itself, i.e. '/home/john/web/manage.py')\n  - default is build using DJANGO_PROJECT_NAME\n\nCRONTAB_DJANGO_SETTINGS_MODULE\n  - dotted python path to the settings module to run the command with\n  - default is the common one from the environment variable and will not be overwritten\n  - since 0.6.0\n\nCRONTAB_PYTHON_EXECUTABLE\n  - path to the python interpreter executable used to run the scheduled job\n  - default uses the interpreter executable used to `add` the jobs (via 'python manage.py crontab add')\n\nCRONTAB_COMMAND_PREFIX\n  - something you wanne do or declare before each job gets executed. A good point for environment variables.\n  - default: '' (empty string)\n  - example: 'STAGE=production'\n\nCRONTAB_COMMAND_SUFFIX\n  - something you wanne do after each job was executed.\n  - default: '' (empty string)\n  - example: '2>&1'\n\nCRONTAB_COMMENT\n  - used for marking the added contab-lines for removing, default value includes project name to distinguish multiple projects on the same host and user\n  - default: 'django-crontabs for ' + CRONTAB_DJANGO_PROJECT_NAME\n\ncontributors\n============\narski cinghiale meric426 justdoit0823 chamaken\n\nfaq\n===\n* **I'm using this old django version (<1.8) and can't install this package. What should i do?**\n  - Yeah, update django of course (!) or - as you seem to be familiar with old, unsupported versions, install the old version of this package too (it support django 1.3-1.7)::\n\n    pip install django-crontab==0.6.0\n\n* **Will it work with windows?**\n  - No.\n* **I'm getting \"bad command\"/\"errors in cronfile\" while installing via \"crontab add\". What's wrong?**\n  - Maybe it's your cron time format, it can have 5 or 6 fields. Check that your system supports 6 or just define 5 in `CRONJOBS`. (see #23)\n\nlicense\n=======\nMIT-License, see LICENSE file.",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "dead simple crontab powered job scheduling for django",
    "version": "0.7.1",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "37bda122ba96167f5dfab70a58ca22fa046b7ef1ebad9ff026f7831bd6c2a49c",
                "md5": "bc9eefc87d907eb6c46e49a1c8fc7c0b",
                "sha256": "1201810a212460aaaa48eb6a766738740daf42c1a4f6aafecfb1525036929236"
            },
            "downloads": -1,
            "filename": "django-crontab-0.7.1.tar.gz",
            "has_sig": false,
            "md5_digest": "bc9eefc87d907eb6c46e49a1c8fc7c0b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7089,
            "upload_time": "2016-03-07T19:35:54",
            "upload_time_iso_8601": "2016-03-07T19:35:54.714528Z",
            "url": "https://files.pythonhosted.org/packages/37/bd/a122ba96167f5dfab70a58ca22fa046b7ef1ebad9ff026f7831bd6c2a49c/django-crontab-0.7.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2016-03-07 19:35:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "kraiz",
    "github_project": "django-crontab",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "django-crontab"
}
        
Elapsed time: 0.03801s