This is an old revision of the document!


Celery - Distributed Task Queue

Instalation

  1. Install RabbitMQ:
    aptitude install rabbitmq-server
    pip install librabbitmq
  2. Install Celery
    pip install celery
    pip install django-celery

(note: make sure there is not south installed on your system when using django >= 1.7)

Django Integration

http://celery.readthedocs.org/en/latest/django/first-steps-with-django.html

  1. Create project celery config projectname/celery.py:
    from __future__ import absolute_import
     
    import os
     
    from celery import Celery
     
    # set the default Django settings module for the 'celery' program.
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'celertest.settings')
     
    from django.conf import settings
     
    #app = Celery('celertest')
    app = Celery('celertest', backend='amqp', broker='amqp://guest@localhost//')
     
     
    # Using a string here means the worker will not have to
    # pickle the object when using Windows.
    app.config_from_object('django.conf:settings')
    app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
     
     
    @app.task(bind=True)
    def debug_task(self):
        print('Request: {0!r}'.format(self.request))
 
python/celery.1434976701.txt.gz · Last modified: 2015/06/22 14:38 by vondra