@@ -29,23 +29,24 @@ Our addition task looks like this:
2929 All celery tasks are classes that inherit from the ``Task ``
3030class. In this case we're using a decorator that wraps the add
3131function in an appropriate class for us automatically. The full
32- documentation on how to create tasks and task classes are in
33- :doc: `Executing Tasks< ../userguide/tasks> `.
32+ documentation on how to create tasks and task classes is in the
33+ :doc: `../userguide/tasks> ` part of the user guide .
3434
3535
3636
3737Configuration
3838=============
3939
40- Celery is configured by using a configuration module. By convention,
41- this module is called ``celeryconfig.py ``. This module must be in the
42- Python path so it can be imported.
40+ Celery is configured by using a configuration module. By default
41+ this module is called ``celeryconfig.py ``.
42+
43+ :Note: This configuration module must be on the Python path so it
44+ can be imported.
4345
4446You can set a custom name for the configuration module with the
45- ``CELERY_CONFIG_MODULE `` variable. In these examples we use the
47+ ``CELERY_CONFIG_MODULE `` variable, but in these examples we use the
4648default name.
4749
48-
4950Let's create our ``celeryconfig.py ``.
5051
51521. Configure how we communicate with the broker::
@@ -61,10 +62,14 @@ Let's create our ``celeryconfig.py``.
6162
6263 CELERY_RESULT_BACKEND = "amqp"
6364
65+ The AMQP backend is non-persistent by default, and you can only
66+ fetch the result of a task once (as it's sent as a message).
67+
64683. Finally, we list the modules to import, that is, all the modules
65- that contain tasks. This is so celery knows about what tasks it can
66- be asked to perform. We only have a single task module,
67- ``tasks.py ``, which we added earlier::
69+ that contain tasks. This is so Celery knows about what tasks it can
70+ be asked to perform.
71+
72+ We only have a single task module, ``tasks.py ``, which we added earlier::
6873
6974 CELERY_IMPORTS = ("tasks", )
7075
@@ -101,43 +106,51 @@ For info on how to run celery as standalone daemon, see
101106Executing the task
102107==================
103108
104- Whenever we want to execute our task, we can use the `` delay `` method
105- of the task class.
109+ Whenever we want to execute our task, we can use the
110+ :meth: ` ~celery.task.base.Task.delay ` method of the task class.
106111
107- This is a handy shortcut to the ``apply_async `` method which gives
108- greater control of the task execution.
109- See :doc: `Executing Tasks<../userguide/executing> ` for more information.
112+ This is a handy shortcut to the :meth: `~celery.task.base.Task.apply_async `
113+ method which gives greater control of the task execution. Read the
114+ :doc: `Executing Tasks<../userguide/executing> ` part of the user guide
115+ for more information about executing tasks.
110116
111117 >>> from tasks import add
112118 >>> add.delay(4 , 4 )
113119 <AsyncResult: 889143a6-39a2-4e52-837b-d80d33efb22d>
114120
115121At this point, the task has been sent to the message broker. The message
116- broker will hold on to the task until a celery worker server has successfully
122+ broker will hold on to the task until a worker server has successfully
117123picked it up.
118124
119125*Note: * If everything is just hanging when you execute ``delay ``, please check
120126that RabbitMQ is running, and that the user/password has access to the virtual
121127host you configured earlier.
122128
123- Right now we have to check the celery worker log files to know what happened
124- with the task. This is because we didn't keep the `` AsyncResult `` object
125- returned by `` delay ` `.
129+ Right now we have to check the worker log files to know what happened
130+ with the task. This is because we didn't keep the :class: ` ~celery.result. AsyncResult `
131+ object returned by :meth: ` ~celery.task.base.Task. delay `.
126132
127- The ``AsyncResult `` lets us find the state of the task, wait for the task to
128- finish and get its return value (or exception if the task failed).
133+ The :class: `~celery.result.AsyncResult ` lets us find the state of the task, wait for
134+ the task to finish, get its return value (or exception if the task failed),
135+ and more.
129136
130- So, let's execute the task again, but this time we'll keep track of the task:
137+ So, let's execute the task again, but this time we'll keep track of the task
138+ by keeping the :class: `~celery.result.AsyncResult `::
131139
132140 >>> result = add.delay(4, 4)
141+
133142 >>> result.ready() # returns True if the task has finished processing.
134143 False
144+
135145 >>> result.result # task is not ready, so no return value yet.
136146 None
147+
137148 >>> result.get() # Waits until the task is done and returns the retval.
138149 8
150+
139151 >>> result.result # direct access to result, doesn't re-raise errors.
140152 8
153+
141154 >>> result.successful() # returns True if the task didn't end in failure.
142155 True
143156
0 commit comments