faq.html 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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.7.0 (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.7.0 (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.7.0 (unstable) documentation" href="index.html" />
  21. <link rel="next" title="Module API Reference" href="reference/index.html" />
  22. <link rel="prev" title="Tutorial: Creating a click counter using carrot and celery" href="tutorials/clickcounter.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="tutorials/clickcounter.html" title="Tutorial: Creating a click counter using carrot and celery"
  39. accesskey="P">previous</a> |</li>
  40. <li><a href="index.html">Celery v0.7.0 (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="mysql-is-throwing-deadlock-errors-what-can-i-do">
  50. <h2>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></h2>
  51. <p><strong>Answer:</strong> MySQL has default isolation level set to <tt class="docutils literal"><span class="pre">REPEATABLE-READ</span></tt>,
  52. if you don&#8217;t really need that, set it to <tt class="docutils literal"><span class="pre">READ-COMMITTED</span></tt>.
  53. You can do that by adding the following to your <tt class="docutils literal"><span class="pre">my.cnf</span></tt>:</p>
  54. <div class="highlight-python"><div class="highlight"><pre><span class="p">[</span><span class="n">mysqld</span><span class="p">]</span>
  55. <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>
  56. </pre></div>
  57. </div>
  58. <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
  59. Transaction Model and Locking</a> in the MySQL user manual.</p>
  60. <p>(Thanks to Honza Kral and Anton Tsigularov for this solution)</p>
  61. </div>
  62. <div class="section" id="celeryd-is-not-doing-anything-just-hanging">
  63. <h2>celeryd is not doing anything, just hanging<a class="headerlink" href="#celeryd-is-not-doing-anything-just-hanging" title="Permalink to this headline">¶</a></h2>
  64. <dl class="docutils">
  65. <dt><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>.</dt>
  66. <dd>or <cite>Why is Task.delay/apply* just hanging?</cite>.</dd>
  67. </dl>
  68. </div>
  69. <div class="section" id="why-is-task-delay-apply-just-hanging">
  70. <h2>Why is Task.delay/apply* just hanging?`<a class="headerlink" href="#why-is-task-delay-apply-just-hanging" title="Permalink to this headline">¶</a></h2>
  71. <p><strong>Answer:</strong> <tt class="xref docutils literal"><span class="pre">amqplib</span></tt> hangs if it isn&#8217;t able to authenticate to the
  72. AMQP server, so make sure you are able to access the configured vhost using
  73. the user and password.</p>
  74. </div>
  75. <div class="section" id="why-won-t-celeryd-run-on-freebsd">
  76. <h2>Why won&#8217;t celeryd run on FreeBSD?<a class="headerlink" href="#why-won-t-celeryd-run-on-freebsd" title="Permalink to this headline">¶</a></h2>
  77. <p><strong>Answer:</strong> multiprocessing.Pool requires a working POSIX semaphore
  78. implementation which isn&#8217;t enabled in FreeBSD by default. You have to enable
  79. POSIX semaphores in the kernel and manually recompile multiprocessing.</p>
  80. </div>
  81. <div class="section" id="i-m-having-integrityerror-duplicate-key-errors-why">
  82. <h2>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></h2>
  83. <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>.
  84. Thanks to howsthedotcom.</p>
  85. </div>
  86. <div class="section" id="why-won-t-my-task-run">
  87. <h2>Why won&#8217;t my Task run?<a class="headerlink" href="#why-won-t-my-task-run" title="Permalink to this headline">¶</a></h2>
  88. <p><strong>Answer:</strong> Did you register the task in the applications <tt class="docutils literal"><span class="pre">tasks.py</span></tt> module?
  89. (or in some other module Django loads by default, like <tt class="docutils literal"><span class="pre">models.py</span></tt>?).
  90. Also there might be syntax errors preventing the tasks module being imported.</p>
  91. <p>You can find out if the celery daemon is able to run the task by executing the
  92. task manually:</p>
  93. <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>
  94. <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>
  95. </pre></div>
  96. </div>
  97. <p>Watch celery daemons logfile (or output if not running as a daemon), to see
  98. if it&#8217;s able to find the task, or if some other error is happening.</p>
  99. </div>
  100. <div class="section" id="why-won-t-my-periodic-task-run">
  101. <h2>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></h2>
  102. <p><strong>Answer:</strong> See <a class="reference internal" href="#why-won-t-my-task-run">Why won&#8217;t my Task run?</a>.</p>
  103. </div>
  104. <div class="section" id="how-do-i-discard-all-waiting-tasks">
  105. <h2>How do I discard all waiting tasks?<a class="headerlink" href="#how-do-i-discard-all-waiting-tasks" title="Permalink to this headline">¶</a></h2>
  106. <p><strong>Answer:</strong> Use <tt class="docutils literal"><span class="pre">celery.task.discard_all()</span></tt>, like this:</p>
  107. <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">discard_all</span>
  108. <span class="gp">&gt;&gt;&gt; </span><span class="n">discard_all</span><span class="p">()</span>
  109. <span class="go">1753</span>
  110. </pre></div>
  111. </div>
  112. <p>The number <tt class="docutils literal"><span class="pre">1753</span></tt> is the number of messages deleted.</p>
  113. <p>You can also start celeryd with the <tt class="docutils literal"><span class="pre">--discard</span></tt> argument which will
  114. accomplish the same thing.</p>
  115. </div>
  116. <div class="section" id="i-ve-discarded-messages-but-there-are-still-messages-left-in-the-queue">
  117. <h2>I&#8217;ve discarded messages, but there are still messages left in the queue?<a class="headerlink" href="#i-ve-discarded-messages-but-there-are-still-messages-left-in-the-queue" title="Permalink to this headline">¶</a></h2>
  118. <p><strong>Answer:</strong> Tasks are acknowledged (removed from the queue) as soon
  119. as they are actually executed. After the worker has received a task, it will
  120. take some time until it is actually executed, especially if there are a lot
  121. of tasks already waiting for execution. Messages that are not acknowledged are
  122. hold on to by the worker until it closes the connection to the broker (AMQP
  123. server). When that connection is closed (e.g because the worker was stopped)
  124. the tasks will be re-sent by the broker to the next available worker (or the
  125. same worker when it has been restarted), so to properly purge the queue of
  126. waiting tasks you have to stop all the workers, and then discard the tasks
  127. using <tt class="docutils literal"><span class="pre">discard_all</span></tt>.</p>
  128. </div>
  129. <div class="section" id="can-i-use-celery-with-activemq-stomp">
  130. <h2>Can I use celery with ActiveMQ/STOMP?<a class="headerlink" href="#can-i-use-celery-with-activemq-stomp" title="Permalink to this headline">¶</a></h2>
  131. <p><strong>Answer</strong>: Yes. But this is somewhat experimental for now.
  132. It is certainly working ok for me in a test configuration, but it has not
  133. been tested in production like RabbitMQ. If you have any problems with
  134. using STOMP and celery, please report the bugs to the issue tracker:</p>
  135. <blockquote>
  136. <a class="reference external" href="http://github.com/ask/celery/issues/">http://github.com/ask/celery/issues/</a></blockquote>
  137. <p>First you have to use the <tt class="docutils literal"><span class="pre">master</span></tt> branch of <tt class="docutils literal"><span class="pre">celery</span></tt>:</p>
  138. <div class="highlight-python"><pre>$ git clone git://github.com/ask/celery.git
  139. $ cd celery
  140. $ sudo python setup.py install
  141. $ cd ..</pre>
  142. </div>
  143. <p>Then you need to install the <tt class="docutils literal"><span class="pre">stompbackend</span></tt> branch of <tt class="docutils literal"><span class="pre">carrot</span></tt>:</p>
  144. <div class="highlight-python"><pre>$ git clone git://github.com/ask/carrot.git
  145. $ cd carrot
  146. $ git checkout stompbackend
  147. $ sudo python setup.py install
  148. $ cd ..</pre>
  149. </div>
  150. <p>And my fork of <tt class="docutils literal"><span class="pre">python-stomp</span></tt> which adds non-blocking support:</p>
  151. <div class="highlight-python"><pre>$ hg clone http://bitbucket.org/asksol/python-stomp/
  152. $ cd python-stomp
  153. $ sudo python setup.py install
  154. $ cd ..</pre>
  155. </div>
  156. <p>In this example we will use a queue called <tt class="docutils literal"><span class="pre">celery</span></tt> which we created in
  157. the ActiveMQ web admin interface.</p>
  158. <p><strong>Note</strong>: For ActiveMQ the queue name has to have <tt class="docutils literal"><span class="pre">&quot;/queue/&quot;</span></tt> prepended to
  159. it. i.e. the queue <tt class="docutils literal"><span class="pre">celery</span></tt> becomes <tt class="docutils literal"><span class="pre">/queue/celery</span></tt>.</p>
  160. <p>Since a STOMP queue is a single named entity and it doesn&#8217;t have the
  161. routing capabilities of AMQP you need to set both the <tt class="docutils literal"><span class="pre">queue</span></tt>, and
  162. <tt class="docutils literal"><span class="pre">exchange</span></tt> settings to your queue name. This is a minor inconvenience since
  163. carrot needs to maintain the same interface for both AMQP and STOMP (obviously
  164. the one with the most capabilities won).</p>
  165. <p>Use the following specific settings in your <tt class="docutils literal"><span class="pre">settings.py</span></tt>:</p>
  166. <div class="highlight-python"><div class="highlight"><pre><span class="c"># Makes python-stomp the default backend for carrot.</span>
  167. <span class="n">CARROT_BACKEND</span> <span class="o">=</span> <span class="s">&quot;stomp&quot;</span>
  168. <span class="c"># STOMP hostname and port settings.</span>
  169. <span class="n">AMQP_HOST</span> <span class="o">=</span> <span class="s">&quot;localhost&quot;</span>
  170. <span class="n">AMQP_PORT</span> <span class="o">=</span> <span class="mf">61613</span>
  171. <span class="c"># The queue name to use (both queue and exchange must be set to the</span>
  172. <span class="c"># same queue name when using STOMP)</span>
  173. <span class="n">CELERY_AMQP_CONSUMER_QUEUE</span> <span class="o">=</span> <span class="s">&quot;/queue/celery&quot;</span>
  174. <span class="n">CELERY_AMQP_EXCHANGE</span> <span class="o">=</span> <span class="s">&quot;/queue/celery&quot;</span>
  175. </pre></div>
  176. </div>
  177. <p>Now you can go on reading the tutorial in the README, ignoring any AMQP
  178. specific options.</p>
  179. </div>
  180. <div class="section" id="which-features-are-not-supported-when-using-stomp">
  181. <h2>Which features are not supported when using STOMP?<a class="headerlink" href="#which-features-are-not-supported-when-using-stomp" title="Permalink to this headline">¶</a></h2>
  182. <p>This is a (possible incomplete) list of features not available when
  183. using the STOMP backend:</p>
  184. <ul class="simple">
  185. <li>routing keys</li>
  186. <li>exchange types (direct, topic, headers, etc)</li>
  187. <li>immediate</li>
  188. <li>mandatory</li>
  189. </ul>
  190. </div>
  191. <div class="section" id="can-i-send-some-tasks-to-only-some-servers">
  192. <h2>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></h2>
  193. <p><strong>Answer:</strong> As of now there is only one use-case that works like this,
  194. and that is 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>,
  195. while tasks 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
  196. handle more than one routing_key, but this is coming in a later release.</p>
  197. <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,
  198. and one server <tt class="docutils literal"><span class="pre">z</span></tt>, that only handles feed related tasks, you can use this
  199. configuration:</p>
  200. <blockquote>
  201. <ul class="simple">
  202. <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>
  203. </ul>
  204. <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>
  205. <span class="n">AMQP_PORT</span> <span class="o">=</span> <span class="mf">5678</span>
  206. <span class="n">AMQP_USER</span> <span class="o">=</span> <span class="s">&quot;myapp&quot;</span>
  207. <span class="n">AMQP_PASSWORD</span> <span class="o">=</span> <span class="s">&quot;secret&quot;</span>
  208. <span class="n">AMQP_VHOST</span> <span class="o">=</span> <span class="s">&quot;myapp&quot;</span>
  209. <span class="n">CELERY_AMQP_CONSUMER_QUEUE</span> <span class="o">=</span> <span class="s">&quot;regular_tasks&quot;</span>
  210. <span class="n">CELERY_AMQP_EXCHANGE</span> <span class="o">=</span> <span class="s">&quot;tasks&quot;</span>
  211. <span class="n">CELERY_AMQP_PUBLISHER_ROUTING_KEY</span> <span class="o">=</span> <span class="s">&quot;task.regular&quot;</span>
  212. <span class="n">CELERY_AMQP_CONSUMER_ROUTING_KEY</span> <span class="o">=</span> <span class="s">&quot;task.#&quot;</span>
  213. <span class="n">CELERY_AMQP_EXCHANGE_TYPE</span> <span class="o">=</span> <span class="s">&quot;topic&quot;</span>
  214. </pre></div>
  215. </div>
  216. <ul class="simple">
  217. <li>Server <tt class="docutils literal"><span class="pre">z</span></tt>: settings.py:</li>
  218. </ul>
  219. <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>
  220. <span class="n">AMQP_PORT</span> <span class="o">=</span> <span class="mf">5678</span>
  221. <span class="n">AMQP_USER</span> <span class="o">=</span> <span class="s">&quot;myapp&quot;</span>
  222. <span class="n">AMQP_PASSWORD</span> <span class="o">=</span> <span class="s">&quot;secret&quot;</span>
  223. <span class="n">AMQP_VHOST</span> <span class="o">=</span> <span class="s">&quot;myapp&quot;</span>
  224. <span class="n">CELERY_AMQP_EXCHANGE</span> <span class="o">=</span> <span class="s">&quot;tasks&quot;</span>
  225. <span class="n">CELERY_AMQP_PUBLISHER_ROUTING_KEY</span> <span class="o">=</span> <span class="s">&quot;task.regular&quot;</span>
  226. <span class="n">CELERY_AMQP_EXCHANGE_TYPE</span> <span class="o">=</span> <span class="s">&quot;topic&quot;</span>
  227. <span class="c"># This is the settings different for this server:</span>
  228. <span class="n">CELERY_AMQP_CONSUMER_QUEUE</span> <span class="o">=</span> <span class="s">&quot;feed_tasks&quot;</span>
  229. <span class="n">CELERY_AMQP_CONSUMER_ROUTING_KEY</span> <span class="o">=</span> <span class="s">&quot;feed.#&quot;</span>
  230. </pre></div>
  231. </div>
  232. </blockquote>
  233. <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
  234. <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>
  235. <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>
  236. <span class="kn">from</span> <span class="nn">celery.task</span> <span class="kn">import</span> <span class="n">Task</span>
  237. <span class="k">class</span> <span class="nc">FeedImportTask</span><span class="p">(</span><span class="n">Task</span><span class="p">):</span>
  238. <span class="n">routing_key</span> <span class="o">=</span> <span class="s">&quot;feed.importer&quot;</span>
  239. <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>
  240. <span class="c"># something importing the feed</span>
  241. <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>
  242. </pre></div>
  243. </div>
  244. <p>You can also override this using the <tt class="docutils literal"><span class="pre">routing_key</span></tt> argument to
  245. <tt class="xref docutils literal"><span class="pre">celery.task.apply_async()</span></tt>:</p>
  246. <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>
  247. <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>
  248. <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>
  249. <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>
  250. </pre></div>
  251. </div>
  252. </div>
  253. <div class="section" id="can-i-use-celery-without-django">
  254. <h2>Can I use celery without Django?<a class="headerlink" href="#can-i-use-celery-without-django" title="Permalink to this headline">¶</a></h2>
  255. <p><strong>Answer:</strong> Yes.</p>
  256. <p>Celery uses something called loaders to read/setup configuration, import
  257. modules that registers tasks and to decide what happens when a task is
  258. executed. Currently there are two loaders, the default loader and the Django
  259. loader. If you want to use celery without a Django project, you either have to
  260. use the default loader, or write a loader of your own.</p>
  261. <p>The rest of this answer describes how to use the default loader.</p>
  262. <p>First of all, installation. You need to get the development version of
  263. celery from github:</p>
  264. <div class="highlight-python"><pre>$ git clone git://github.com/ask/celery.git
  265. $ cd celery
  266. # python setup.py install # as root</pre>
  267. </div>
  268. <p>While it is possible to use celery from outside of Django, we still need
  269. Django itself to run, this is to use the ORM and cache-framework, etc.
  270. Duplicating these features would be time consuming and mostly pointless, so
  271. we decided that having a dependency on Django itself was a good thing.
  272. Install Django using your favorite install tool, <tt class="docutils literal"><span class="pre">easy_install</span></tt>, <tt class="docutils literal"><span class="pre">pip</span></tt>, or
  273. whatever:</p>
  274. <div class="highlight-python"><div class="highlight"><pre><span class="c"># easy_install django # as root</span>
  275. </pre></div>
  276. </div>
  277. <p>You need a configuration file named <tt class="docutils literal"><span class="pre">celeryconfig.py</span></tt>, either in the
  278. directory you run <tt class="docutils literal"><span class="pre">celeryd</span></tt> in, or in a Python library path where it is
  279. able to find it. The configuration file can contain any of the settings
  280. described in <a title="" class="reference external" href="reference/celery.conf.html#module-celery.conf"><tt class="xref docutils literal"><span class="pre">celery.conf</span></tt></a>, and in additional if you&#8217;re using the
  281. database backend you have to configure the database. Here is an example
  282. configuration using the database backend with MySQL:</p>
  283. <div class="highlight-python"><div class="highlight"><pre><span class="c"># Broker configuration</span>
  284. <span class="n">AMQP_SERVER</span> <span class="o">=</span> <span class="s">&quot;localhost&quot;</span>
  285. <span class="n">AMQP_PORT</span> <span class="o">=</span> <span class="s">&quot;5672&quot;</span>
  286. <span class="n">AMQP_VHOST</span> <span class="o">=</span> <span class="s">&quot;celery&quot;</span>
  287. <span class="n">AMQP_USER</span> <span class="o">=</span> <span class="s">&quot;celery&quot;</span>
  288. <span class="n">AMQP_PASSWORD</span> <span class="o">=</span> <span class="s">&quot;celerysecret&quot;</span>
  289. <span class="n">CARROT_BACKEND</span><span class="o">=</span><span class="s">&quot;amqp&quot;</span>
  290. <span class="c"># Using the database backend.</span>
  291. <span class="n">CELERY_BACKEND</span> <span class="o">=</span> <span class="s">&quot;database&quot;</span>
  292. <span class="n">DATABASE_ENGINE</span> <span class="o">=</span> <span class="s">&quot;mysql&quot;</span> <span class="c"># see Django docs for a description of these.</span>
  293. <span class="n">DATABASE_NAME</span> <span class="o">=</span> <span class="s">&quot;mydb&quot;</span>
  294. <span class="n">DATABASE_HOST</span> <span class="o">=</span> <span class="s">&quot;mydb.example.org&quot;</span>
  295. <span class="n">DATABASE_USER</span> <span class="o">=</span> <span class="s">&quot;myuser&quot;</span>
  296. <span class="n">DATABASE_PASSWORD</span> <span class="o">=</span> <span class="s">&quot;mysecret&quot;</span>
  297. <span class="c"># Number of processes that processes tasks simultaneously.</span>
  298. <span class="n">CELERYD_CONCURRENCY</span> <span class="o">=</span> <span class="mf">8</span>
  299. <span class="c"># Modules to import when celeryd starts.</span>
  300. <span class="c"># This must import every module where you register tasks so celeryd</span>
  301. <span class="c"># is able to find and run them.</span>
  302. <span class="n">CELERY_IMPORTS</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;mytaskmodule1&quot;</span><span class="p">,</span> <span class="s">&quot;mytaskmodule2&quot;</span><span class="p">)</span>
  303. </pre></div>
  304. </div>
  305. <p>Now with this configuration file in the current directory you have to
  306. run <tt class="docutils literal"><span class="pre">celeryinit</span></tt> to create the database tables:</p>
  307. <div class="highlight-python"><pre>$ celeryinit</pre>
  308. </div>
  309. <p>Then you should be able to successfully run <tt class="docutils literal"><span class="pre">celeryd</span></tt>:</p>
  310. <div class="highlight-python"><pre>$ celeryd --loglevel=INFO</pre>
  311. </div>
  312. <p>and send a task from a python shell (note that it must be able to import
  313. <tt class="docutils literal"><span class="pre">celeryconfig.py</span></tt>):</p>
  314. <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.builtins</span> <span class="kn">import</span> <span class="n">PingTask</span>
  315. <span class="gp">&gt;&gt;&gt; </span><span class="n">result</span> <span class="o">=</span> <span class="n">PingTask</span><span class="o">.</span><span class="n">apply_async</span><span class="p">()</span>
  316. <span class="gp">&gt;&gt;&gt; </span><span class="n">result</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
  317. <span class="go">&#39;pong&#39;</span>
  318. </pre></div>
  319. </div>
  320. </div>
  321. </div>
  322. </div>
  323. </div>
  324. </div>
  325. <div class="sphinxsidebar">
  326. <div class="sphinxsidebarwrapper">
  327. <h3><a href="index.html">Table Of Contents</a></h3>
  328. <ul>
  329. <li><a class="reference external" href="">Frequently Asked Questions</a><ul>
  330. <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>
  331. <li><a class="reference external" href="#celeryd-is-not-doing-anything-just-hanging">celeryd is not doing anything, just hanging</a></li>
  332. <li><a class="reference external" href="#why-is-task-delay-apply-just-hanging">Why is Task.delay/apply* just hanging?`</a></li>
  333. <li><a class="reference external" href="#why-won-t-celeryd-run-on-freebsd">Why won&#8217;t celeryd run on FreeBSD?</a></li>
  334. <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>
  335. <li><a class="reference external" href="#why-won-t-my-task-run">Why won&#8217;t my Task run?</a></li>
  336. <li><a class="reference external" href="#why-won-t-my-periodic-task-run">Why won&#8217;t my Periodic Task run?</a></li>
  337. <li><a class="reference external" href="#how-do-i-discard-all-waiting-tasks">How do I discard all waiting tasks?</a></li>
  338. <li><a class="reference external" href="#i-ve-discarded-messages-but-there-are-still-messages-left-in-the-queue">I&#8217;ve discarded messages, but there are still messages left in the queue?</a></li>
  339. <li><a class="reference external" href="#can-i-use-celery-with-activemq-stomp">Can I use celery with ActiveMQ/STOMP?</a></li>
  340. <li><a class="reference external" href="#which-features-are-not-supported-when-using-stomp">Which features are not supported when using STOMP?</a></li>
  341. <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>
  342. <li><a class="reference external" href="#can-i-use-celery-without-django">Can I use celery without Django?</a></li>
  343. </ul>
  344. </li>
  345. </ul>
  346. <h4>Previous topic</h4>
  347. <p class="topless"><a href="tutorials/clickcounter.html"
  348. title="previous chapter">Tutorial: Creating a click counter using carrot and celery</a></p>
  349. <h4>Next topic</h4>
  350. <p class="topless"><a href="reference/index.html"
  351. title="next chapter">Module API Reference</a></p>
  352. <h3>This Page</h3>
  353. <ul class="this-page-menu">
  354. <li><a href="sources/faq.txt"
  355. rel="nofollow">Show Source</a></li>
  356. </ul>
  357. <div id="searchbox" style="display: none">
  358. <h3>Quick search</h3>
  359. <form class="search" action="search.html" method="get">
  360. <input type="text" name="q" size="18" />
  361. <input type="submit" value="Go" />
  362. <input type="hidden" name="check_keywords" value="yes" />
  363. <input type="hidden" name="area" value="default" />
  364. </form>
  365. <p class="searchtip" style="font-size: 90%">
  366. Enter search terms or a module, class or function name.
  367. </p>
  368. </div>
  369. <script type="text/javascript">$('#searchbox').show(0);</script>
  370. </div>
  371. </div>
  372. <div class="clearer"></div>
  373. </div>
  374. <div class="related">
  375. <h3>Navigation</h3>
  376. <ul>
  377. <li class="right" style="margin-right: 10px">
  378. <a href="genindex.html" title="General Index"
  379. >index</a></li>
  380. <li class="right" >
  381. <a href="modindex.html" title="Global Module Index"
  382. >modules</a> |</li>
  383. <li class="right" >
  384. <a href="reference/index.html" title="Module API Reference"
  385. >next</a> |</li>
  386. <li class="right" >
  387. <a href="tutorials/clickcounter.html" title="Tutorial: Creating a click counter using carrot and celery"
  388. >previous</a> |</li>
  389. <li><a href="index.html">Celery v0.7.0 (unstable) documentation</a> &raquo;</li>
  390. </ul>
  391. </div>
  392. <div class="footer">
  393. &copy; Copyright 2009, Ask Solem.
  394. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.2.
  395. </div>
  396. </body>
  397. </html>