faq.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Frequently Asked Questions &mdash; Celery v0.3.20 (unstable) documentation</title>
  7. <link rel="stylesheet" href="static/nature.css" type="text/css" />
  8. <link rel="stylesheet" href="static/pygments.css" type="text/css" />
  9. <script type="text/javascript">
  10. var DOCUMENTATION_OPTIONS = {
  11. URL_ROOT: '',
  12. VERSION: '0.3.20 (unstable)',
  13. COLLAPSE_MODINDEX: false,
  14. FILE_SUFFIX: '.html',
  15. HAS_SOURCE: true
  16. };
  17. </script>
  18. <script type="text/javascript" src="static/jquery.js"></script>
  19. <script type="text/javascript" src="static/doctools.js"></script>
  20. <link rel="top" title="Celery v0.3.20 (unstable) documentation" href="index.html" />
  21. <link rel="next" title="Module API Reference" href="reference/index.html" />
  22. <link rel="prev" title="celery - Distributed Task Queue for Django." href="introduction.html" />
  23. </head>
  24. <body>
  25. <div class="related">
  26. <h3>Navigation</h3>
  27. <ul>
  28. <li class="right" style="margin-right: 10px">
  29. <a href="genindex.html" title="General Index"
  30. accesskey="I">index</a></li>
  31. <li class="right" >
  32. <a href="modindex.html" title="Global Module Index"
  33. accesskey="M">modules</a> |</li>
  34. <li class="right" >
  35. <a href="reference/index.html" title="Module API Reference"
  36. accesskey="N">next</a> |</li>
  37. <li class="right" >
  38. <a href="introduction.html" title="celery - Distributed Task Queue for Django."
  39. accesskey="P">previous</a> |</li>
  40. <li><a href="index.html">Celery v0.3.20 (unstable) documentation</a> &raquo;</li>
  41. </ul>
  42. </div>
  43. <div class="document">
  44. <div class="documentwrapper">
  45. <div class="bodywrapper">
  46. <div class="body">
  47. <div class="section" id="frequently-asked-questions">
  48. <h1>Frequently Asked Questions<a class="headerlink" href="#frequently-asked-questions" title="Permalink to this headline">¶</a></h1>
  49. <div class="section" id="questions">
  50. <h2>Questions<a class="headerlink" href="#questions" title="Permalink to this headline">¶</a></h2>
  51. <div class="section" id="mysql-is-throwing-deadlock-errors-what-can-i-do">
  52. <h3>MySQL is throwing deadlock errors, what can I do?<a class="headerlink" href="#mysql-is-throwing-deadlock-errors-what-can-i-do" title="Permalink to this headline">¶</a></h3>
  53. <p><strong>Answer:</strong> MySQL has default isolation level set to <tt class="docutils literal"><span class="pre">REPEATABLE-READ</span></tt>,
  54. if you don&#8217;t really need that, set it to <tt class="docutils literal"><span class="pre">READ-COMMITTED</span></tt>.
  55. You can do that by adding the following to your <tt class="docutils literal"><span class="pre">my.cnf</span></tt>:</p>
  56. <div class="highlight-python"><div class="highlight"><pre><span class="p">[</span><span class="n">mysqld</span><span class="p">]</span>
  57. <span class="n">transaction</span><span class="o">-</span><span class="n">isolation</span> <span class="o">=</span> <span class="n">READ</span><span class="o">-</span><span class="n">COMMITTED</span>
  58. </pre></div>
  59. </div>
  60. <p>For more information about InnoDBs transaction model see <a class="reference external" href="http://dev.mysql.com/doc/refman/5.1/en/innodb-transaction-model.html">MySQL - The InnoDB
  61. Transaction Model and Locking</a> in the MySQL user manual.</p>
  62. <p>(Thanks to Honza Kral and Anton Tsigularov for this solution)</p>
  63. </div>
  64. <div class="section" id="celeryd-is-not-doing-anything-just-hanging">
  65. <h3>celeryd is not doing anything, just hanging<a class="headerlink" href="#celeryd-is-not-doing-anything-just-hanging" title="Permalink to this headline">¶</a></h3>
  66. <p><strong>Answer:</strong> See <a class="reference internal" href="#mysql-is-throwing-deadlock-errors-what-can-i-do">MySQL is throwing deadlock errors, what can I do?</a>.</p>
  67. </div>
  68. <div class="section" id="i-m-having-integrityerror-duplicate-key-errors-why">
  69. <h3>I&#8217;m having <tt class="docutils literal"><span class="pre">IntegrityError:</span> <span class="pre">Duplicate</span> <span class="pre">Key</span></tt> errors. Why?<a class="headerlink" href="#i-m-having-integrityerror-duplicate-key-errors-why" title="Permalink to this headline">¶</a></h3>
  70. <p><strong>Answer:</strong> See <a class="reference internal" href="#mysql-is-throwing-deadlock-errors-what-can-i-do">MySQL is throwing deadlock errors, what can I do?</a>.
  71. Thanks to howsthedotcom.</p>
  72. </div>
  73. <div class="section" id="why-won-t-my-task-run">
  74. <h3>Why won&#8217;t my Task run?<a class="headerlink" href="#why-won-t-my-task-run" title="Permalink to this headline">¶</a></h3>
  75. <p><strong>Answer:</strong> Did you register the task in the applications <tt class="docutils literal"><span class="pre">tasks.py</span></tt> module?
  76. (or in some other module Django loads by default, like <tt class="docutils literal"><span class="pre">models.py</span></tt>?).
  77. Also there might be syntax errors preventing the tasks module being imported.</p>
  78. <p>You can find out if the celery daemon is able to run the task by executing the
  79. task manually:</p>
  80. <div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">myapp.tasks</span> <span class="kn">import</span> <span class="n">MyPeriodicTask</span>
  81. <span class="gp">&gt;&gt;&gt; </span><span class="n">MyPeriodicTask</span><span class="o">.</span><span class="n">delay</span><span class="p">()</span>
  82. </pre></div>
  83. </div>
  84. <p>Watch celery daemons logfile (or output if not running as a daemon), to see
  85. if it&#8217;s able to find the task, or if some other error is happening.</p>
  86. </div>
  87. <div class="section" id="why-won-t-my-periodic-task-run">
  88. <h3>Why won&#8217;t my Periodic Task run?<a class="headerlink" href="#why-won-t-my-periodic-task-run" title="Permalink to this headline">¶</a></h3>
  89. <p>See <a class="reference internal" href="#why-won-t-my-task-run">Why won&#8217;t my Task run?</a>.</p>
  90. </div>
  91. <div class="section" id="can-i-send-some-tasks-to-only-some-servers">
  92. <h3>Can I send some tasks to only some servers?<a class="headerlink" href="#can-i-send-some-tasks-to-only-some-servers" title="Permalink to this headline">¶</a></h3>
  93. <p>As of now there is only one use-case that works like this, and that is
  94. tasks of type <tt class="docutils literal"><span class="pre">A</span></tt> can be sent to servers <tt class="docutils literal"><span class="pre">x</span></tt> and <tt class="docutils literal"><span class="pre">y</span></tt>, while tasks
  95. of type <tt class="docutils literal"><span class="pre">B</span></tt> can be sent to server <tt class="docutils literal"><span class="pre">z</span></tt>. One server can&#8217;t handle more than
  96. one routing_key, but this is coming in a later release.</p>
  97. <p>Say you have two servers, <tt class="docutils literal"><span class="pre">x</span></tt>, and <tt class="docutils literal"><span class="pre">y</span></tt> that handles regular tasks,
  98. and one server <tt class="docutils literal"><span class="pre">z</span></tt>, that only handles feed related tasks, you can use this
  99. configuration:</p>
  100. <blockquote>
  101. <ul class="simple">
  102. <li>Servers <tt class="docutils literal"><span class="pre">x</span></tt> and <tt class="docutils literal"><span class="pre">y</span></tt>: settings.py:</li>
  103. </ul>
  104. <div class="highlight-python"><div class="highlight"><pre><span class="n">AMQP_SERVER</span> <span class="o">=</span> <span class="s">&quot;rabbit&quot;</span>
  105. <span class="n">AMQP_PORT</span> <span class="o">=</span> <span class="mf">5678</span>
  106. <span class="n">AMQP_USER</span> <span class="o">=</span> <span class="s">&quot;myapp&quot;</span>
  107. <span class="n">AMQP_PASSWORD</span> <span class="o">=</span> <span class="s">&quot;secret&quot;</span>
  108. <span class="n">AMQP_VHOST</span> <span class="o">=</span> <span class="s">&quot;myapp&quot;</span>
  109. <span class="n">CELERY_AMQP_CONSUMER_QUEUE</span> <span class="o">=</span> <span class="s">&quot;regular_tasks&quot;</span>
  110. <span class="n">CELERY_AMQP_EXCHANGE</span> <span class="o">=</span> <span class="s">&quot;tasks&quot;</span>
  111. <span class="n">CELERY_AMQP_PUBLISHER_ROUTING_KEY</span> <span class="o">=</span> <span class="s">&quot;task.regular&quot;</span>
  112. <span class="n">CELERY_AMQP_CONSUMER_ROUTING_KEY</span> <span class="o">=</span> <span class="s">&quot;task.#&quot;</span>
  113. <span class="n">CELERY_AMQP_EXCHANGE_TYPE</span> <span class="o">=</span> <span class="s">&quot;topic&quot;</span>
  114. </pre></div>
  115. </div>
  116. <ul class="simple">
  117. <li>Server <tt class="docutils literal"><span class="pre">z</span></tt>: settings.py:</li>
  118. </ul>
  119. <div class="highlight-python"><div class="highlight"><pre><span class="n">AMQP_SERVER</span> <span class="o">=</span> <span class="s">&quot;rabbit&quot;</span>
  120. <span class="n">AMQP_PORT</span> <span class="o">=</span> <span class="mf">5678</span>
  121. <span class="n">AMQP_USER</span> <span class="o">=</span> <span class="s">&quot;myapp&quot;</span>
  122. <span class="n">AMQP_PASSWORD</span> <span class="o">=</span> <span class="s">&quot;secret&quot;</span>
  123. <span class="n">AMQP_VHOST</span> <span class="o">=</span> <span class="s">&quot;myapp&quot;</span>
  124. <span class="n">CELERY_AMQP_EXCHANGE</span> <span class="o">=</span> <span class="s">&quot;tasks&quot;</span>
  125. <span class="n">CELERY_AMQP_PUBLISHER_ROUTING_KEY</span> <span class="o">=</span> <span class="s">&quot;task.regular&quot;</span>
  126. <span class="n">CELERY_AMQP_EXCHANGE_TYPE</span> <span class="o">=</span> <span class="s">&quot;topic&quot;</span>
  127. <span class="c"># This is the settings different for this server:</span>
  128. <span class="n">CELERY_AMQP_CONSUMER_QUEUE</span> <span class="o">=</span> <span class="s">&quot;feed_tasks&quot;</span>
  129. <span class="n">CELERY_AMQP_CONSUMER_ROUTING_KEY</span> <span class="o">=</span> <span class="s">&quot;feed.#&quot;</span>
  130. </pre></div>
  131. </div>
  132. </blockquote>
  133. <p>Now to make a Task run on the <tt class="docutils literal"><span class="pre">z</span></tt> server you need to set its
  134. <tt class="docutils literal"><span class="pre">routing_key</span></tt> attribute so it starts with the words <tt class="docutils literal"><span class="pre">&quot;task.feed.&quot;</span></tt>:</p>
  135. <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">feedaggregator.models</span> <span class="kn">import</span> <span class="n">Feed</span>
  136. <span class="kn">from</span> <span class="nn">celery.task</span> <span class="kn">import</span> <span class="n">Task</span>
  137. <span class="k">class</span> <span class="nc">FeedImportTask</span><span class="p">(</span><span class="n">Task</span><span class="p">):</span>
  138. <span class="n">name</span> <span class="o">=</span> <span class="s">&quot;import_feed&quot;</span>
  139. <span class="n">routing_key</span> <span class="o">=</span> <span class="s">&quot;feed.importer&quot;</span>
  140. <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">feed_url</span><span class="p">):</span>
  141. <span class="c"># something importing the feed</span>
  142. <span class="n">Feed</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">import_feed</span><span class="p">(</span><span class="n">feed_url</span><span class="p">)</span>
  143. </pre></div>
  144. </div>
  145. <p>You can also override this using the <tt class="docutils literal"><span class="pre">routing_key</span></tt> argument to
  146. <tt class="xref docutils literal"><span class="pre">celery.task.apply_async()</span></tt>:</p>
  147. <div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">celery.task</span> <span class="kn">import</span> <span class="n">apply_async</span>
  148. <span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">myapp.tasks</span> <span class="kn">import</span> <span class="n">RefreshFeedTask</span>
  149. <span class="gp">&gt;&gt;&gt; </span><span class="n">apply_async</span><span class="p">(</span><span class="n">RefreshFeedTask</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="s">&quot;http://cnn.com/rss&quot;</span><span class="p">],</span>
  150. <span class="gp">... </span> <span class="n">routing_key</span><span class="o">=</span><span class="s">&quot;feed.importer&quot;</span><span class="p">)</span>
  151. </pre></div>
  152. </div>
  153. </div>
  154. </div>
  155. </div>
  156. </div>
  157. </div>
  158. </div>
  159. <div class="sphinxsidebar">
  160. <div class="sphinxsidebarwrapper">
  161. <h3><a href="index.html">Table Of Contents</a></h3>
  162. <ul>
  163. <li><a class="reference external" href="">Frequently Asked Questions</a><ul>
  164. <li><a class="reference external" href="#questions">Questions</a><ul>
  165. <li><a class="reference external" href="#mysql-is-throwing-deadlock-errors-what-can-i-do">MySQL is throwing deadlock errors, what can I do?</a></li>
  166. <li><a class="reference external" href="#celeryd-is-not-doing-anything-just-hanging">celeryd is not doing anything, just hanging</a></li>
  167. <li><a class="reference external" href="#i-m-having-integrityerror-duplicate-key-errors-why">I&#8217;m having <tt class="docutils literal"><span class="pre">IntegrityError:</span> <span class="pre">Duplicate</span> <span class="pre">Key</span></tt> errors. Why?</a></li>
  168. <li><a class="reference external" href="#why-won-t-my-task-run">Why won&#8217;t my Task run?</a></li>
  169. <li><a class="reference external" href="#why-won-t-my-periodic-task-run">Why won&#8217;t my Periodic Task run?</a></li>
  170. <li><a class="reference external" href="#can-i-send-some-tasks-to-only-some-servers">Can I send some tasks to only some servers?</a></li>
  171. </ul>
  172. </li>
  173. </ul>
  174. </li>
  175. </ul>
  176. <h4>Previous topic</h4>
  177. <p class="topless"><a href="introduction.html"
  178. title="previous chapter">celery - Distributed Task Queue for Django.</a></p>
  179. <h4>Next topic</h4>
  180. <p class="topless"><a href="reference/index.html"
  181. title="next chapter">Module API Reference</a></p>
  182. <h3>This Page</h3>
  183. <ul class="this-page-menu">
  184. <li><a href="sources/faq.txt"
  185. rel="nofollow">Show Source</a></li>
  186. </ul>
  187. <div id="searchbox" style="display: none">
  188. <h3>Quick search</h3>
  189. <form class="search" action="search.html" method="get">
  190. <input type="text" name="q" size="18" />
  191. <input type="submit" value="Go" />
  192. <input type="hidden" name="check_keywords" value="yes" />
  193. <input type="hidden" name="area" value="default" />
  194. </form>
  195. <p class="searchtip" style="font-size: 90%">
  196. Enter search terms or a module, class or function name.
  197. </p>
  198. </div>
  199. <script type="text/javascript">$('#searchbox').show(0);</script>
  200. </div>
  201. </div>
  202. <div class="clearer"></div>
  203. </div>
  204. <div class="related">
  205. <h3>Navigation</h3>
  206. <ul>
  207. <li class="right" style="margin-right: 10px">
  208. <a href="genindex.html" title="General Index"
  209. >index</a></li>
  210. <li class="right" >
  211. <a href="modindex.html" title="Global Module Index"
  212. >modules</a> |</li>
  213. <li class="right" >
  214. <a href="reference/index.html" title="Module API Reference"
  215. >next</a> |</li>
  216. <li class="right" >
  217. <a href="introduction.html" title="celery - Distributed Task Queue for Django."
  218. >previous</a> |</li>
  219. <li><a href="index.html">Celery v0.3.20 (unstable) documentation</a> &raquo;</li>
  220. </ul>
  221. </div>
  222. <div class="footer">
  223. &copy; Copyright 2009, Ask Solem.
  224. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.2.
  225. </div>
  226. </body>
  227. </html>