Pyres is an excellent attempt of porting the Resque job queue to python. Pyres-django aims to be just a small collection of helpers for simple integration of pyres to django.
Pyres-django is yet unstable and perhaps not completely production-ready solution. Basically, this is just a set of my own shortcuts moved to a separate django application.
- Ensure that Pyres is installed and working.
- Checkout the app code to your project path:
git clone git://github.com/ruthenium/pyres_django.git
- Add 'pyres_django' to your INSTALLED_APPS.
- If needed, set the REDIS_HOST and REDIS_PORT config settings.
And that's it! Now everything should work.
- Redis server.
- Pyres and its dependencies.
- Django 1.3 or higher (because of class-based views in the web ui).
- Pyres-Scheduler 2.0.3
In your urls.py
add:
import pyres_django
pyres_django.autodiscover()
Adding this will autodiscover all periodic jobs to be executed.
Create a tasks.py
file inside your app folder. Add a class strating with Periodic
or Interval, add a perform()
function and a queue attribute as stated in pyres. You should also add a run every
for adding cron-like functionality as described in APScheduler.
Lets take an example.
class IntervalMyJob(object):
queue = "high"
run_every = {'second': 2}
@staticmethod
def perform(args):
print 'This will be seen every 2 seconds: %s' % args
and
class PeriodicMyJob(object):
queue = "high"
# Schedule a backup to run once from Monday to Friday at 5:30 (am)
run_every = {'month': '6-8,11-12', 'day': '3rd fri', 'hour': '0-3'}
@staticmethod
def perform():
print 'This will be seen every once from Monday to Friday at 5:30 (am)'
Import the get_pyres helper:
from pyres_django import get_pyres
Then anywhere in your code just do:
get_pyres().enqueue(SomeJob, *some_args)
Just type into your console:
$ QUEUES=q1,q2,high python2 manage.py pyres_worker
And worker should run. If you would like to permanently define a queues list for it, you can set the PYRES_QUEUES variable in your settings.py.
Include pyres_django's urls.py as you usually do in your global urls.py:
urlpatterns = patterns('', url('^my-prefix/', include('pyres_django.urls')), )
And now it will be available under your specified prefix.
According to the current implementation of the original ResWeb, It is not possible to use it under django without any patches. So I've had to re-implement the resweb-functionality my own way. It is still a "quick-and-dirty" solution, and I don't plan to develop it further, because the API of pyres is still not stablized and the ability of wsgi-integration of course will present in future versions.
Although, the basic implementation of a "True-way" wsgi integration can be found in the "wsgi" branch of this app.
- binarydud - an author of original pyres and resweb.
- alex - an author of the django-wsgi
- 2degrees - the authors of the twod.wsgi
- c-oreills - the author of the pyres-scheduler
- mzupan
- geros