Skip to content

Commit

Permalink
Started on the next-steps tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
ask committed May 9, 2012
1 parent 2802c72 commit 6fa86eb
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/getting-started/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
introduction
brokers/index
first-steps-with-celery
next-steps
resources
74 changes: 74 additions & 0 deletions docs/getting-started/next-steps.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
============
Next Steps
============

The :ref:`first-steps` guide is intentionally minimal. In this guide
we will demonstrate what Celery offers in more detail, including
how to add Celery support for your application and library.


Our Project
===========

Project layout::

proj/__init__.py
/celery.py
/tasks.py

:file:`proj/celery.py`

.. literalinclude:: ../../examples/next-steps/proj/celery.py
:language python:


:file:`proj/tasks.py`

.. literalinclude:: ../../examples/next-steps/proj/tasks.py
:language python:



Subtasks
========


group
-----

.. code-block:: python
>>> from celery import group
>>> from proj.tasks import add
>>> ~group(add.s(i, i) for i in xrange(10))
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
>>> group(add.s(i, i) for i in xrange(10)).skew(1, 10)
map/starmap
-------------

.. code-block:: python
>>> from proj.tasks import add
>>> ~xsum.map([range(10), range(100)])
[45, 4950]
>>> ~add.starmap(zip(range(10), range(10)))
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
>>> add.starmap(zip(range(10), range(10))).apply_async(countdown=10)
chunks
------

.. code-block:: python
>>> from proj.tasks import add
>>> ~add.chunks(zip(range(100), range(100)), 10)
Empty file.
11 changes: 11 additions & 0 deletions examples/next-steps/proj/celery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from __future__ import absolute_import

from celery import Celery

celery = Celery("proj", broker="amqp://", backend="amqp")
celery.conf.CELERY_IMPORTS = ("proj.tasks", )

if __name__ == "__main__":
from billiard import freeze_support
freeze_support()
celery.start()
18 changes: 18 additions & 0 deletions examples/next-steps/proj/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import absolute_import

from proj.celery import celery


@celery.task
def add(x, y):
return x + y


@celery.task
def mul(x, y):
return x * y


@celery.task
def xsum(numbers):
return sum(numbers)

0 comments on commit 6fa86eb

Please sign in to comment.