{ "info": { "author": "Matthew Tretter", "author_email": "matthew@exanimo.com", "bugtrack_url": null, "classifiers": [], "description": "Periodically lets you define periodic tasks in Python, and then run them however you want (think cron job).\n\n\nGoals\n-------\n\n1. Tasks and their schedules should be defined in Python\u2014not crontabs or the database.\n2. There should be multiple ways to trigger tasks, but only one syntax for defining them. Just because you trigger your tasks with a cron job on one server doesn't mean you can always do that. When you can't, you shouldn't have to rewrite all your code\u2014just change a setting.\n3. The system should be highly flexible, but\u2026\n4. \u2026there should be shortcuts for the most common schedules (hourly, daily, etc.).\n5. The system should try to recover gracefully, but\u2026\n6. \u2026it should also alert the administrators if anything goes wrong.\n\n\nInstallation\n------------\n\n1. `pip install git+https://github.com/hzdg/django-periodically.git#egg=django-periodically`\n2. Add 'periodically' to your `INSTALLED_APPS` in settings.py.\n3. `python manage.py syncdb`\n\n\nUsage\n-----\n\nDefining and Scheduling Tasks\n``````````````````````````````\n\nPeriodically gives you a few ways to schedule periodic tasks. The easiest is to use the included decorators:\n\n.. code-block:: python\n\n from periodically.decorators import *\n\n @hourly()\n def my_task():\n print 'Do something!'\n\n @every(minutes=45)\n def my_other_task():\n print 'Do something else every 45 minutes!'\n\nHowever, you can also define task classes:\n\n.. code-block:: python\n\n from periodically.tasks import PeriodicTask\n from periodically import register\n from periodically.schedules import Daily\n\n # Define the task.\n class MyTask(PeriodicTask):\n def run(self):\n print 'Do something.'\n\n # Schedule the task.\n register.task(MyTask(), Daily())\n\nTasks can be scheduled anywhere in your project, but Periodically automatically looks for a `periodictasks` module in your `INSTALLED_APPS`, so it's probably a good idea to define all your tasks in `myapp/periodictasks.py`.\n\nRunning Your Tasks\n``````````````````\n\nPeriodically uses a pluggable backend system to decouple the defining and scheduling of your tasks from their execution. **The default backend will not run your tasks automatically**, so you need to tell it to by using the `runtasks` management command. Generally, you would use a cronjob (or similar) to do this. For example, placing the following line in your crontab file would check for tasks that need to be run every five minutes:\n\n.. code-block:: python\n\n */5 * * * * python /path/to/manage.py runtasks\n\n### Scheduler Backends\n\nOne of the things that makes Periodically so flexible is its scheduler backend system. A single project can even use multiple backends!\n\nUsing Custom Backends\n`````````````````````\n\nIn `settings.py`:\n\n.. code-block:: python\n\n\tPERIODICALLY = {\n\t\t...\n\t 'SCHEDULERS': {\n 'special': {\n 'backend': 'myapp.MySpecialBackend',\n },\n },\n }\n\nThen, in your app's `periodictasks.py` file:\n\n.. code-block:: python\n\n @hourly(backend='special')\n def do_something():\n\t\tprint 'Doing something!'\n\nThis setup works great for scheduling a specific task with a particular backend, but if you find that you want to change the backend that all of your tasks use, it's easier to just override the default:\n\n.. code-block:: python\n\n PERIODICALLY = {\n ...\n 'SCHEDULERS': {\n 'default': {\n 'backend': 'myapp.MySpecialBackend',\n },\n },\n }\n\nWith the above code in your `settings.py` file, all tasks will use `myapp.MySpecialBackend` by default.\n\nBackend Groups\n``````````````\n\nSometimes it's convenient to create backend groups. A good example of this is when you have several different backends that should all be triggered by a cron job. Here's how you add backends to groups in your `settings.py` file:\n\n.. code-block:: python\n\n\tPERIODICALLY = {\n\t\t...\n\t 'SCHEDULERS': {\n\t\t\t'default': {\n\t\t\t\t'backend': 'myapp.MySpecialBackend',\n\t\t\t\t'groups': ['cron'],\n\t\t\t},\n\t\t\t'special': {\n\t\t\t\t'backend': 'myapp.MySpecialBackend',\n\t\t\t\t'groups': ['cron'],\n\t\t\t},\n\t\t\t'another': {\n\t\t\t\t'backend': 'myapp.AnotherBackend',\n\t\t\t},\n\t },\n\t}\n\nNow you'll be able to use the `--group` option of the `runtasks` management command to selectively run tasks:\n.. code-block:: python\n\n python manage.py runtasks --group cron\n\nYour crontab would now look like this:\n.. code-block:: python\n\n*/5 * * * * python /path/to/manage.py runtasks --group cron\n\nTIP\n```\n\nIf you plan to use a cron job to trigger task execution, it's a good idea to always create a \"cron\" group. That way, if you ever add new non-cron backends, you won't have to change your crontab; you just won't add your new backend to the \"cron\" group.\n\n\nLogging\n```````\n\nPeriodically uses Django's logging system to let you know when something goes wrong. To enable this, just add a \"periodically\" logger to your `settings.py` file:\n\n.. code-block:: python\n\n LOGGING = {\n\t ...\n # This part should be in your settings file by default.\n 'handlers': {\n 'mail_admins': {\n 'level': 'ERROR',\n 'class': 'django.utils.log.AdminEmailHandler'\n }\n },\n 'loggers': {\n ...\n # Add the following to enable logging for Periodically.\n 'periodically': {\n 'handlers': ['mail_admins'],\n 'level': 'ERROR',\n 'propagate': True,\n },\n },\n }\n\nThis is a relatively simple setup that will send an email to the site admins whenever a periodic task fails, but Django is capable of much more. For more information, check out [the Django docs](https://docs.djangoproject.com/en/dev/topics/logging/).", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/hzdg/django-periodically", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "django-periodically", "package_url": "https://pypi.org/project/django-periodically/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-periodically/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/hzdg/django-periodically" }, "release_url": "https://pypi.org/project/django-periodically/0.3.0/", "requires_dist": null, "requires_python": null, "summary": "Periodic task management for your Django projects.", "version": "0.3.0" }, "last_serial": 3651977, "releases": { "0.3.0": [ { "comment_text": "", "digests": { "md5": "418d0efdb49ce6e8ec206f6d89091560", "sha256": "70e6d265880e32d3351548b80c90f81d246f986f6434425d343ef099487a5513" }, "downloads": -1, "filename": "django-periodically-0.3.0.tar.gz", "has_sig": false, "md5_digest": "418d0efdb49ce6e8ec206f6d89091560", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14150, "upload_time": "2014-06-10T13:47:28", "url": "https://files.pythonhosted.org/packages/c3/23/63520f8c44306becd23660c3ceac7f4b0918df640f3b3b539ea4e7f3f93d/django-periodically-0.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "418d0efdb49ce6e8ec206f6d89091560", "sha256": "70e6d265880e32d3351548b80c90f81d246f986f6434425d343ef099487a5513" }, "downloads": -1, "filename": "django-periodically-0.3.0.tar.gz", "has_sig": false, "md5_digest": "418d0efdb49ce6e8ec206f6d89091560", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14150, "upload_time": "2014-06-10T13:47:28", "url": "https://files.pythonhosted.org/packages/c3/23/63520f8c44306becd23660c3ceac7f4b0918df640f3b3b539ea4e7f3f93d/django-periodically-0.3.0.tar.gz" } ] }