next-steps.rst 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. ============
  2. Next Steps
  3. ============
  4. The :ref:`first-steps` guide is intentionally minimal. In this guide
  5. we will demonstrate what Celery offers in more detail, including
  6. how to add Celery support for your application and library.
  7. Our Project
  8. ===========
  9. Project layout::
  10. proj/__init__.py
  11. /celery.py
  12. /tasks.py
  13. :file:`proj/celery.py`
  14. .. literalinclude:: ../../examples/next-steps/proj/celery.py
  15. :language python:
  16. :file:`proj/tasks.py`
  17. .. literalinclude:: ../../examples/next-steps/proj/tasks.py
  18. :language python:
  19. Subtasks
  20. ========
  21. group
  22. -----
  23. .. code-block:: python
  24. >>> from celery import group
  25. >>> from proj.tasks import add
  26. >>> ~group(add.s(i, i) for i in xrange(10))
  27. [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
  28. >>> group(add.s(i, i) for i in xrange(10)).skew(1, 10)
  29. map/starmap
  30. -------------
  31. .. code-block:: python
  32. >>> from proj.tasks import add
  33. >>> ~xsum.map([range(10), range(100)])
  34. [45, 4950]
  35. >>> ~add.starmap(zip(range(10), range(10)))
  36. [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
  37. >>> add.starmap(zip(range(10), range(10))).apply_async(countdown=10)
  38. chunks
  39. ------
  40. .. code-block:: python
  41. >>> from proj.tasks import add
  42. >>> ~add.chunks(zip(range(100), range(100)), 10)