README.rst 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. ==============================================================
  2. Example Django project using Celery
  3. ==============================================================
  4. Contents
  5. ========
  6. ``proj/``
  7. ---------
  8. This is the project iself, created using
  9. ``django-admin.py startproject proj``, and then the settings module
  10. (``proj/settings.py``) was modified to add ``demoapp`` to
  11. ``INSTALLED_APPS``
  12. ``proj/celery.py``
  13. ----------
  14. This module contains the Celery application instance for this project,
  15. we take configuration from Django settings and use ``autodiscover_tasks`` to
  16. find task modules inside all packages listed in ``INSTALLED_APPS``.
  17. ``demoapp/``
  18. ------------
  19. Example generic app. This is decoupled from the rest of the project by using
  20. the ``@shared_task`` decorator. This decorator returns a proxy that always
  21. points to the currently active Celery instance.
  22. Installing requirements
  23. =======================
  24. The settings file assumes that ``rabbitmq-server`` is running on ``localhost``
  25. using the default ports. More information here:
  26. http://docs.celeryproject.org/en/latest/getting-started/brokers/rabbitmq.html
  27. In addition, some Python requirements must also be satisfied:
  28. .. code-block:: console
  29. $ pip install -r requirements.txt
  30. Starting the worker
  31. ===================
  32. .. code-block:: console
  33. $ celery -A proj worker -l info
  34. Running a task
  35. ===================
  36. .. code-block:: console
  37. $ python ./manage.py shell
  38. >>> from demoapp.tasks import add, mul, xsum
  39. >>> res = add.delay(2,3)
  40. >>> res.get()
  41. 5