Thursday 15 October 2015

django celery

Using the Django ORM/Cache as a result backend.

If you want to store task results in the Django database then you still need to install thedjango-celery library for that (alternatively you can use the SQLAlchemy result backend).
The django-celery library implements result backends using the Django ORM and the Django Cache frameworks.
To use this extension in your project you need to follow these four steps:
  1. Install the django-celery library:
    $ pip install django-celery
    
  2. Add djcelery to INSTALLED_APPS.
  3. Create the celery database tables.
    This step will create the tables used to store results when using the database result backend and the tables used by the database periodic task scheduler. You can skip this step if you don’t use these.
    If you are using south for schema migrations, you’ll want to:
    $ python manage.py migrate djcelery
    
    For those who are not using south, a normal syncdb will work:
    $ python manage.py syncdb
    
  4. Configure celery to use the django-celery backend.
    For the database backend you must use:
    app.conf.update(
        CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend',
    )
    
    For the cache backend you can use:
    app.conf.update(
        CELERY_RESULT_BACKEND='djcelery.backends.cache:CacheBackend',
    )
    
    If you have connected Celery to your Django settings then you can add this directly into your settings module (without the app.conf.update part)

No comments:

Post a Comment