|
@@ -5,13 +5,13 @@
|
|
|
<head>
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
|
|
|
- <title>celery - Distributed Task Queue for Django. — Celery v0.2.14 documentation</title>
|
|
|
+ <title>celery - Distributed Task Queue for Django. — Celery v0.3.0 (unstable) documentation</title>
|
|
|
<link rel="stylesheet" href="static/agogo.css" type="text/css" />
|
|
|
<link rel="stylesheet" href="static/pygments.css" type="text/css" />
|
|
|
<script type="text/javascript">
|
|
|
var DOCUMENTATION_OPTIONS = {
|
|
|
URL_ROOT: '',
|
|
|
- VERSION: '0.2.14',
|
|
|
+ VERSION: '0.3.0 (unstable)',
|
|
|
COLLAPSE_MODINDEX: false,
|
|
|
FILE_SUFFIX: '.html',
|
|
|
HAS_SOURCE: true
|
|
@@ -19,7 +19,7 @@
|
|
|
</script>
|
|
|
<script type="text/javascript" src="static/jquery.js"></script>
|
|
|
<script type="text/javascript" src="static/doctools.js"></script>
|
|
|
- <link rel="top" title="Celery v0.2.14 documentation" href="index.html" />
|
|
|
+ <link rel="top" title="Celery v0.3.0 (unstable) documentation" href="index.html" />
|
|
|
<link rel="next" title="Frequently Asked Questions" href="faq.html" />
|
|
|
<link rel="prev" title="Welcome to Celery’s documentation!" href="index.html" />
|
|
|
</head>
|
|
@@ -27,7 +27,7 @@
|
|
|
|
|
|
<div class="header-wrapper">
|
|
|
<div class="header">
|
|
|
- <h1><a href="index.html">Celery v0.2.14 documentation</a></h1>
|
|
|
+ <h1><a href="index.html">Celery v0.3.0 (unstable) documentation</a></h1>
|
|
|
<div class="rel">
|
|
|
<a href="genindex.html" title="General Index"
|
|
|
accesskey="I">index</a> |
|
|
@@ -54,7 +54,7 @@
|
|
|
<col class="field-name" />
|
|
|
<col class="field-body" />
|
|
|
<tbody valign="top">
|
|
|
-<tr class="field"><th class="field-name">Version:</th><td class="field-body">0.2.10</td>
|
|
|
+<tr class="field"><th class="field-name">Version:</th><td class="field-body">0.3.0</td>
|
|
|
</tr>
|
|
|
</tbody>
|
|
|
</table>
|
|
@@ -103,7 +103,7 @@ and the return value if completed, or exception on failure.</li>
|
|
|
</div>
|
|
|
<div class="section" id="api-reference-documentation">
|
|
|
<h2>API Reference Documentation<a class="headerlink" href="#api-reference-documentation" title="Permalink to this headline">¶</a></h2>
|
|
|
-<p>The <a class="reference internal" href="#api-reference-documentation">API Reference Documentation</a> is hosted at Github
|
|
|
+<p>The <a class="reference external" href="http://ask.github.com/celery/">API Reference</a> is hosted at Github
|
|
|
(<a class="reference external" href="http://ask.github.com/celery">http://ask.github.com/celery</a>)</p>
|
|
|
</div>
|
|
|
<div class="section" id="installation">
|
|
@@ -126,9 +126,52 @@ by doing the following,:</p>
|
|
|
<h2>Usage<a class="headerlink" href="#usage" title="Permalink to this headline">¶</a></h2>
|
|
|
<div class="section" id="installing-rabbitmq">
|
|
|
<h3>Installing RabbitMQ<a class="headerlink" href="#installing-rabbitmq" title="Permalink to this headline">¶</a></h3>
|
|
|
+<p>See <a class="reference external" href="http://www.rabbitmq.com/install.html">Installing RabbitMQ</a> over at RabbitMQ’s website. For Mac OS X
|
|
|
+see <a class="reference external" href="http://playtype.net/past/2008/10/9/installing_rabbitmq_on_osx/">Installing RabbitMQ on OS X</a>.</p>
|
|
|
+</div>
|
|
|
+<div class="section" id="setting-up-rabbitmq">
|
|
|
+<h3>Setting up RabbitMQ<a class="headerlink" href="#setting-up-rabbitmq" title="Permalink to this headline">¶</a></h3>
|
|
|
+<p>To use celery we need to create a RabbitMQ user, a virtual host and
|
|
|
+allow that user access to that virtual host:</p>
|
|
|
+<div class="highlight-python"><pre>$ rabbitmqctl add_user myuser mypassword
|
|
|
+
|
|
|
+$ rabbitmqctl add_vhost myvhost
|
|
|
+
|
|
|
+$ rabbitmqctl map_user_vhost myuser myvhost</pre>
|
|
|
+</div>
|
|
|
</div>
|
|
|
<div class="section" id="configuring-your-django-project-to-use-celery">
|
|
|
<h3>Configuring your Django project to use Celery<a class="headerlink" href="#configuring-your-django-project-to-use-celery" title="Permalink to this headline">¶</a></h3>
|
|
|
+<p>You only need three simple steps to use celery with your Django project.</p>
|
|
|
+<ol class="arabic">
|
|
|
+<li><p class="first">Add <tt class="docutils literal"><span class="pre">celery</span></tt> to <tt class="docutils literal"><span class="pre">INSTALLED_APPS</span></tt>.</p>
|
|
|
+</li>
|
|
|
+<li><p class="first">Create the celery database tables:</p>
|
|
|
+<div class="highlight-python"><pre>$ python manage.py syncdb</pre>
|
|
|
+</div>
|
|
|
+</li>
|
|
|
+<li><dl class="first docutils">
|
|
|
+<dt>Configure celery to use the AMQP user and virtual host we created</dt>
|
|
|
+<dd><p class="first">before, by adding the following to your <tt class="docutils literal"><span class="pre">settings.py</span></tt>:</p>
|
|
|
+<div class="last highlight-python"><div class="highlight"><pre><span class="n">AMQP_HOST</span> <span class="o">=</span> <span class="s">"localhost"</span>
|
|
|
+<span class="n">AMQP_PORT</span> <span class="o">=</span> <span class="mf">5672</span>
|
|
|
+<span class="n">AMQP_USER</span> <span class="o">=</span> <span class="s">"myuser"</span>
|
|
|
+<span class="n">AMQP_PASSWORD</span> <span class="o">=</span> <span class="s">"mypassword"</span>
|
|
|
+<span class="n">AMQP_VHOST</span> <span class="o">=</span> <span class="s">"myvhost"</span>
|
|
|
+</pre></div>
|
|
|
+</div>
|
|
|
+</dd>
|
|
|
+</dl>
|
|
|
+</li>
|
|
|
+</ol>
|
|
|
+<p>That’s it.</p>
|
|
|
+<p>There are more options available, like how many processes you want to process
|
|
|
+work in parallel (the <tt class="docutils literal"><span class="pre">CELERY_CONCURRENCY</span></tt> setting), and the backend used
|
|
|
+for storing task statuses. But for now, this should do. For all of the options
|
|
|
+available, please consult the <a class="reference external" href="http://ask.github.com/celery/">API Reference</a></p>
|
|
|
+<p><strong>Note</strong>: If you’re using SQLite as the Django database back-end,
|
|
|
+<tt class="docutils literal"><span class="pre">celeryd</span></tt> will only be able to process one task at a time, this is
|
|
|
+because SQLite doesn’t allow concurrent writes.</p>
|
|
|
</div>
|
|
|
<div class="section" id="running-the-celery-worker-daemon">
|
|
|
<h3>Running the celery worker daemon<a class="headerlink" href="#running-the-celery-worker-daemon" title="Permalink to this headline">¶</a></h3>
|
|
@@ -144,9 +187,6 @@ background as a daemon instead:</p>
|
|
|
help command:</p>
|
|
|
<div class="highlight-python"><pre>$ python manage.py help celeryd</pre>
|
|
|
</div>
|
|
|
-<p><strong>Note</strong>: If you’re using <tt class="docutils literal"><span class="pre">SQLite</span></tt> as the Django database back-end,
|
|
|
-<tt class="docutils literal"><span class="pre">celeryd</span></tt> will only be able to process one task at a time, this is
|
|
|
-because <tt class="docutils literal"><span class="pre">SQLite</span></tt> doesn’t allow concurrent writes.</p>
|
|
|
</div>
|
|
|
<div class="section" id="defining-and-executing-tasks">
|
|
|
<h3>Defining and executing tasks<a class="headerlink" href="#defining-and-executing-tasks" title="Permalink to this headline">¶</a></h3>
|
|
@@ -154,17 +194,17 @@ because <tt class="docutils literal"><span class="pre">SQLite</span></tt> doesn&
|
|
|
be defined in the python shell or ipython/bpython. This is because the celery
|
|
|
worker server needs access to the task function to be able to run it.
|
|
|
So while it looks like we use the python shell to define the tasks in these
|
|
|
-examples, you can’t do it this way. Put them in your Django applications
|
|
|
-<tt class="docutils literal"><span class="pre">tasks</span></tt> module (the worker daemon will automatically load any <tt class="docutils literal"><span class="pre">tasks.py</span></tt>
|
|
|
+examples, you can’t do it this way. Put them in the <tt class="docutils literal"><span class="pre">tasks</span></tt> module of your
|
|
|
+Django application. The worker daemon will automatically load any <tt class="docutils literal"><span class="pre">tasks.py</span></tt>
|
|
|
file for all of the applications listed in <tt class="docutils literal"><span class="pre">settings.INSTALLED_APPS</span></tt>.
|
|
|
-Execution tasks using <tt class="docutils literal"><span class="pre">delay</span></tt> and <tt class="docutils literal"><span class="pre">apply_async</span></tt> can be done from the
|
|
|
+Executing tasks using <tt class="docutils literal"><span class="pre">delay</span></tt> and <tt class="docutils literal"><span class="pre">apply_async</span></tt> can be done from the
|
|
|
python shell, but keep in mind that since arguments are pickled, you can’t
|
|
|
use custom classes defined in the shell session.</p>
|
|
|
-<p>While you can use regular functions, the recommended way is creating
|
|
|
-a task class, this way you can cleanly upgrade the task to use the more
|
|
|
+<p>While you can use regular functions, the recommended way is to define
|
|
|
+a task class. With this way you can cleanly upgrade the task to use the more
|
|
|
advanced features of celery later.</p>
|
|
|
<p>This is a task that basically does nothing but take some arguments,
|
|
|
-and return value:</p>
|
|
|
+and return a value:</p>
|
|
|
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="k">class</span> <span class="nc">MyTask</span><span class="p">(</span><span class="n">Task</span><span class="p">):</span>
|
|
|
<span class="gp">... </span> <span class="n">name</span> <span class="o">=</span> <span class="s">"myapp.mytask"</span>
|
|
|
<span class="gp">... </span> <span class="k">def</span> <span class="nf">run</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">some_arg</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
|
|
@@ -184,11 +224,10 @@ you greater control of the task execution).</p>
|
|
|
<p>At this point, the task has been sent to the message broker. The message
|
|
|
broker will hold on to the task until a celery worker server has successfully
|
|
|
picked it up.</p>
|
|
|
-<p>Now the task has been executed, but to know what happened with the task we
|
|
|
-have to check the celery logfile to see its return value and output.
|
|
|
-This is because we didn’t keep the <tt class="docutils literal"><span class="pre">AsyncResult</span></tt> object returned by
|
|
|
-<tt class="docutils literal"><span class="pre">delay</span></tt>.</p>
|
|
|
-<p>The <tt class="docutils literal"><span class="pre">AsyncResult</span></tt> lets us find out the state of the task, wait for the task to
|
|
|
+<p>Right now we have to check the celery worker logfiles to know what happened with
|
|
|
+the task. This is because we didn’t keep the <tt class="docutils literal"><span class="pre">AsyncResult</span></tt> object returned
|
|
|
+by <tt class="docutils literal"><span class="pre">delay</span></tt>.</p>
|
|
|
+<p>The <tt class="docutils literal"><span class="pre">AsyncResult</span></tt> lets us find the state of the task, wait for the task to
|
|
|
finish and get its return value (or exception if the task failed).</p>
|
|
|
<p>So, let’s execute the task again, but this time we’ll keep track of the task:</p>
|
|
|
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">result</span> <span class="o">=</span> <span class="n">MyTask</span><span class="o">.</span><span class="n">delay</span><span class="p">(</span><span class="s">"do_something"</span><span class="p">,</span> <span class="n">some_arg</span><span class="o">=</span><span class="s">"foo bar baz"</span><span class="p">)</span>
|
|
@@ -233,8 +272,6 @@ Here’s an example of a periodic task:</p>
|
|
|
</div>
|
|
|
<p><strong>Note:</strong> Periodic tasks does not support arguments, as this doesn’t
|
|
|
really make sense.</p>
|
|
|
-<p>For periodic tasks to work you need to add <tt class="docutils literal"><span class="pre">celery</span></tt> to <tt class="docutils literal"><span class="pre">INSTALLED_APPS</span></tt>,
|
|
|
-and issue a <tt class="docutils literal"><span class="pre">syncdb</span></tt>.</p>
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="section" id="license">
|
|
@@ -263,6 +300,7 @@ file in the top distribution directory for the full license text.</p>
|
|
|
</li>
|
|
|
<li class="toctree-l1"><a class="reference external" href="faq.html">Frequently Asked Questions</a></li>
|
|
|
<li class="toctree-l1"><a class="reference external" href="reference/index.html">Module API Reference</a></li>
|
|
|
+<li class="toctree-l1"><a class="reference external" href="changelog.html">Change history</a></li>
|
|
|
</ul>
|
|
|
|
|
|
<h3 style="margin-top: 1.5em;">Search</h3>
|