faq.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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.2 (unstable) documentation</title>
  7. <link rel="stylesheet" href="static/agogo.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.2 (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.2 (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="header-wrapper">
  26. <div class="header">
  27. <h1><a href="index.html">Celery v0.3.2 (unstable) documentation</a></h1>
  28. <div class="rel">
  29. <a href="genindex.html" title="General Index"
  30. accesskey="I">index</a> |
  31. <a href="modindex.html" title="Global Module Index"
  32. accesskey="M">modules</a> |
  33. <a href="reference/index.html" title="Module API Reference"
  34. accesskey="N">next</a> |
  35. <a href="introduction.html" title="celery - Distributed Task Queue for Django."
  36. accesskey="P">previous</a>
  37. </div>
  38. </div>
  39. </div>
  40. <div class="content-wrapper">
  41. <div class="content">
  42. <div class="document">
  43. <div class="documentwrapper">
  44. <div class="bodywrapper">
  45. <div class="body">
  46. <div class="section" id="frequently-asked-questions">
  47. <h1>Frequently Asked Questions<a class="headerlink" href="#frequently-asked-questions" title="Permalink to this headline">¶</a></h1>
  48. <div class="section" id="questions">
  49. <h2>Questions<a class="headerlink" href="#questions" title="Permalink to this headline">¶</a></h2>
  50. <div class="section" id="mysql-is-throwing-deadlock-errors-what-can-i-do">
  51. <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>
  52. <p><strong>Answer:</strong> MySQL has default isolation level set to <tt class="docutils literal"><span class="pre">REPEATABLE-READ</span></tt>,
  53. if you don&#8217;t really need that, set it to <tt class="docutils literal"><span class="pre">READ-COMMITTED</span></tt>.
  54. You can do that by adding the following to your <tt class="docutils literal"><span class="pre">my.cnf</span></tt>:</p>
  55. <div class="highlight-python"><div class="highlight"><pre><span class="p">[</span><span class="n">mysqld</span><span class="p">]</span>
  56. <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>
  57. </pre></div>
  58. </div>
  59. <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
  60. Transaction Model and Locking</a> in the MySQL user manual.</p>
  61. <p>(Thanks to Honza Kral and Anton Tsigularov for this solution)</p>
  62. </div>
  63. <div class="section" id="celeryd-is-not-doing-anything-just-hanging">
  64. <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>
  65. <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>
  66. </div>
  67. <div class="section" id="i-m-having-integrityerror-duplicate-key-errors-why">
  68. <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>
  69. <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>.
  70. Thanks to howsthedotcom.</p>
  71. </div>
  72. <div class="section" id="why-won-t-my-task-run">
  73. <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>
  74. <p><strong>Answer:</strong> Did you register the task in the applications <tt class="docutils literal"><span class="pre">tasks.py</span></tt> module?
  75. (or in some other module Django loads by default, like <tt class="docutils literal"><span class="pre">models.py</span></tt>?).
  76. Also there might be syntax errors preventing the tasks module being imported.</p>
  77. <p>You can find out if the celery daemon is able to run the task by executing the
  78. task manually:</p>
  79. <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>
  80. <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>
  81. </pre></div>
  82. </div>
  83. <p>Watch celery daemons logfile (or output if not running as a daemon), to see
  84. if it&#8217;s able to find the task, or if some other error is happening.</p>
  85. </div>
  86. <div class="section" id="why-won-t-my-periodic-task-run">
  87. <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>
  88. <p>See <a class="reference internal" href="#why-won-t-my-task-run">Why won&#8217;t my Task run?</a>.</p>
  89. </div>
  90. <div class="section" id="can-i-send-some-tasks-to-only-some-servers">
  91. <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>
  92. <p>As of now there is only one use-case that works like this, and that is
  93. 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
  94. 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
  95. one routing_key, but this is coming in a later release.</p>
  96. <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,
  97. and one server <tt class="docutils literal"><span class="pre">z</span></tt>, that only handles feed related tasks, you can use this
  98. configuration:</p>
  99. <blockquote>
  100. <ul class="simple">
  101. <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>
  102. </ul>
  103. <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>
  104. <span class="n">AMQP_PORT</span> <span class="o">=</span> <span class="mf">5678</span>
  105. <span class="n">AMQP_USER</span> <span class="o">=</span> <span class="s">&quot;myapp&quot;</span>
  106. <span class="n">AMQP_PASSWORD</span> <span class="o">=</span> <span class="s">&quot;secret&quot;</span>
  107. <span class="n">AMQP_VHOST</span> <span class="o">=</span> <span class="s">&quot;myapp&quot;</span>
  108. <span class="n">CELERY_AMQP_CONSUMER_QUEUE</span> <span class="o">=</span> <span class="s">&quot;regular_tasks&quot;</span>
  109. <span class="n">CELERY_AMQP_EXCHANGE</span> <span class="o">=</span> <span class="s">&quot;tasks&quot;</span>
  110. <span class="n">CELERY_AMQP_PUBLISHER_ROUTING_KEY</span> <span class="o">=</span> <span class="s">&quot;task.regular&quot;</span>
  111. <span class="n">CELERY_AMQP_CONSUMER_ROUTING_KEY</span> <span class="o">=</span> <span class="s">&quot;task.#&quot;</span>
  112. <span class="n">CELERY_AMQP_EXCHANGE_TYPE</span> <span class="o">=</span> <span class="s">&quot;topic&quot;</span>
  113. </pre></div>
  114. </div>
  115. <ul class="simple">
  116. <li>Server <tt class="docutils literal"><span class="pre">z</span></tt>: settings.py:</li>
  117. </ul>
  118. <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>
  119. <span class="n">AMQP_PORT</span> <span class="o">=</span> <span class="mf">5678</span>
  120. <span class="n">AMQP_USER</span> <span class="o">=</span> <span class="s">&quot;myapp&quot;</span>
  121. <span class="n">AMQP_PASSWORD</span> <span class="o">=</span> <span class="s">&quot;secret&quot;</span>
  122. <span class="n">AMQP_VHOST</span> <span class="o">=</span> <span class="s">&quot;myapp&quot;</span>
  123. <span class="n">CELERY_AMQP_CONSUMER_QUEUE</span> <span class="o">=</span> <span class="s">&quot;feed_tasks&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_CONSUMER_ROUTING_KEY</span> <span class="o">=</span> <span class="s">&quot;task.feed.#&quot;</span>
  127. <span class="n">CELERY_AMQP_EXCHANGE_TYPE</span> <span class="o">=</span> <span class="s">&quot;topic&quot;</span>
  128. </pre></div>
  129. </div>
  130. </blockquote>
  131. <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
  132. <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>
  133. <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>
  134. <span class="kn">from</span> <span class="nn">celery.task</span> <span class="kn">import</span> <span class="n">Task</span>
  135. <span class="k">class</span> <span class="nc">FeedImportTask</span><span class="p">(</span><span class="n">Task</span><span class="p">):</span>
  136. <span class="n">name</span> <span class="o">=</span> <span class="s">&quot;import_feed&quot;</span>
  137. <span class="n">routing_key</span> <span class="o">=</span> <span class="s">&quot;task.feed.importer&quot;</span>
  138. <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>
  139. <span class="c"># something importing the feed</span>
  140. <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>
  141. </pre></div>
  142. </div>
  143. <p>You can also override this using the <tt class="docutils literal"><span class="pre">routing_key</span></tt> argument to
  144. <a title="celery.task.apply_async" class="reference external" href="reference/celery.task.html#celery.task.apply_async"><tt class="xref docutils literal"><span class="pre">celery.task.apply_async()</span></tt></a>:</p>
  145. <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>
  146. <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>
  147. <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>
  148. <span class="gp">... </span> <span class="n">routing_key</span><span class="o">=</span><span class="s">&quot;task.feed.importer&quot;</span><span class="p">)</span>
  149. </pre></div>
  150. </div>
  151. </div>
  152. </div>
  153. </div>
  154. </div>
  155. </div>
  156. </div>
  157. </div>
  158. <div class="sidebar">
  159. <h3>Contents</h3>
  160. <ul class="current">
  161. <li class="toctree-l1"><a class="reference external" href="introduction.html">celery - Distributed Task Queue for Django.</a></li>
  162. <li class="toctree-l1 current"><a class="current reference external" href="">Frequently Asked Questions</a><ul>
  163. <li class="toctree-l2"><a class="reference external" href="#questions">Questions</a></li>
  164. </ul>
  165. </li>
  166. <li class="toctree-l1"><a class="reference external" href="reference/index.html">Module API Reference</a></li>
  167. <li class="toctree-l1"><a class="reference external" href="changelog.html">Change history</a></li>
  168. </ul>
  169. <h3 style="margin-top: 1.5em;">Search</h3>
  170. <form class="search" action="search.html" method="get">
  171. <input type="text" name="q" size="18" />
  172. <input type="submit" value="Go" />
  173. <input type="hidden" name="check_keywords" value="yes" />
  174. <input type="hidden" name="area" value="default" />
  175. </form>
  176. <p class="searchtip" style="font-size: 90%">
  177. Enter search terms or a module, class or function name.
  178. </p>
  179. </div>
  180. <div class="clearer"></div>
  181. </div>
  182. </div>
  183. <div class="footer-wrapper">
  184. <div class="footer">
  185. <div class="left">
  186. <a href="genindex.html" title="General Index"
  187. >index</a> |
  188. <a href="modindex.html" title="Global Module Index"
  189. >modules</a> |
  190. <a href="reference/index.html" title="Module API Reference"
  191. >next</a> |
  192. <a href="introduction.html" title="celery - Distributed Task Queue for Django."
  193. >previous</a>
  194. <br/>
  195. <a href="sources/faq.txt"
  196. rel="nofollow">Show Source</a>
  197. </div>
  198. <div class="right">
  199. &copy; Copyright 2009, Ask Solem.<br/>
  200. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.1.
  201. </div>
  202. <div class="clearer"></div>
  203. </div>
  204. </div>
  205. </body>
  206. </html>