|
| 1 | +Getting started |
| 2 | +=============== |
| 3 | + |
| 4 | +To use :pypi:`django-celery-results` with your project you need to follow these steps: |
| 5 | + |
| 6 | +#. Install the :pypi:`django-celery-results` library: |
| 7 | + |
| 8 | + .. code-block:: console |
| 9 | +
|
| 10 | + $ pip install django-celery-results |
| 11 | +
|
| 12 | +#. Add ``django_celery_results`` to ``INSTALLED_APPS`` in your |
| 13 | + Django project's :file:`settings.py`:: |
| 14 | + |
| 15 | + INSTALLED_APPS = ( |
| 16 | + ..., |
| 17 | + 'django_celery_results', |
| 18 | + ) |
| 19 | + |
| 20 | + Note that there is no dash in the module name, only underscores. |
| 21 | + |
| 22 | +#. Create the Celery database tables by performing a database migrations: |
| 23 | + |
| 24 | + .. code-block:: console |
| 25 | +
|
| 26 | + $ python manage.py migrate django_celery_results |
| 27 | +
|
| 28 | +#. Configure Celery to use the :pypi:`django-celery-results` backend. |
| 29 | + |
| 30 | + Assuming you are using Django's :file:`settings.py` to also configure |
| 31 | + Celery, add the following settings: |
| 32 | + |
| 33 | + .. code-block:: python |
| 34 | +
|
| 35 | + CELERY_RESULT_BACKEND = 'django-db' |
| 36 | +
|
| 37 | + For the cache backend you can use: |
| 38 | + |
| 39 | + .. code-block:: python |
| 40 | +
|
| 41 | + CELERY_CACHE_BACKEND = 'django-cache' |
| 42 | +
|
| 43 | + We can also use the cache defined in the CACHES setting in django. |
| 44 | + |
| 45 | + .. code-block:: python |
| 46 | +
|
| 47 | + # celery setting. |
| 48 | + CELERY_CACHE_BACKEND = 'default' |
| 49 | +
|
| 50 | + # django setting. |
| 51 | + CACHES = { |
| 52 | + 'default': { |
| 53 | + 'BACKEND': 'django.core.cache.backends.db.DatabaseCache', |
| 54 | + 'LOCATION': 'my_cache_table', |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + If you want to include extended information about your tasks remember to enable the `result_extended` setting. |
| 59 | + More information here: https://docs.celeryq.dev/en/stable/userguide/configuration.html#result-extended |
| 60 | + |
| 61 | + .. code-block:: python |
| 62 | + |
| 63 | + CELERY_RESULT_EXTENDED = True |
| 64 | +
|
0 commit comments