celery.worker.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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>Multiprocessing Worker - celery.worker &mdash; Celery v0.1.14 documentation</title>
  7. <link rel="stylesheet" href="../static/default.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.1.14',
  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.1.14 documentation" href="../index.html" />
  21. <link rel="next" title="Backends - celery.backends" href="celery.backends.html" />
  22. <link rel="prev" title="Task Discovery - celery.discovery" href="celery.discovery.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="celery.backends.html" title="Backends - celery.backends"
  36. accesskey="N">next</a> |</li>
  37. <li class="right" >
  38. <a href="celery.discovery.html" title="Task Discovery - celery.discovery"
  39. accesskey="P">previous</a> |</li>
  40. <li><a href="../index.html">Celery v0.1.14 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="module-celery.worker">
  48. <h1>Multiprocessing Worker - celery.worker<a class="headerlink" href="#module-celery.worker" title="Permalink to this headline">¶</a></h1>
  49. <p>celery.worker</p>
  50. <dl class="exception">
  51. <dt id="celery.worker.EmptyQueue">
  52. <em class="property">
  53. exception </em><tt class="descclassname">celery.worker.</tt><tt class="descname">EmptyQueue</tt><a class="headerlink" href="#celery.worker.EmptyQueue" title="Permalink to this definition">¶</a></dt>
  54. <dd>The message queue is currently empty.</dd></dl>
  55. <dl class="class">
  56. <dt id="celery.worker.TaskDaemon">
  57. <em class="property">
  58. class </em><tt class="descclassname">celery.worker.</tt><tt class="descname">TaskDaemon</tt><big>(</big><em>concurrency=None</em>, <em>logfile=None</em>, <em>loglevel=None</em>, <em>queue_wakeup_after=None</em><big>)</big><a class="headerlink" href="#celery.worker.TaskDaemon" title="Permalink to this definition">¶</a></dt>
  59. <dd><p>Executes tasks waiting in the task queue.</p>
  60. <dl class="attribute">
  61. <dt id="celery.worker.TaskDaemon.concurrency">
  62. <tt class="descname">concurrency</tt><a class="headerlink" href="#celery.worker.TaskDaemon.concurrency" title="Permalink to this definition">¶</a></dt>
  63. <dd>The number of simultaneous processes doing work (default:
  64. <tt class="docutils literal"><span class="pre">celery.conf.DAEMON_CONCURRENCY</span></tt>)</dd></dl>
  65. <dl class="attribute">
  66. <dt id="celery.worker.TaskDaemon.loglevel">
  67. <tt class="descname">loglevel</tt><a class="headerlink" href="#celery.worker.TaskDaemon.loglevel" title="Permalink to this definition">¶</a></dt>
  68. <dd>The loglevel used (default: <tt class="docutils literal"><span class="pre">logging.INFO</span></tt>)</dd></dl>
  69. <dl class="attribute">
  70. <dt id="celery.worker.TaskDaemon.logfile">
  71. <tt class="descname">logfile</tt><a class="headerlink" href="#celery.worker.TaskDaemon.logfile" title="Permalink to this definition">¶</a></dt>
  72. <dd>The logfile used, if no logfile is specified it uses <tt class="docutils literal"><span class="pre">stderr</span></tt>
  73. (default: <tt class="docutils literal"><span class="pre">celery.conf.DAEMON_LOG_FILE</span></tt>).</dd></dl>
  74. <dl class="attribute">
  75. <dt id="celery.worker.TaskDaemon.queue_wakeup_after">
  76. <tt class="descname">queue_wakeup_after</tt><a class="headerlink" href="#celery.worker.TaskDaemon.queue_wakeup_after" title="Permalink to this definition">¶</a></dt>
  77. <dd>The time it takes for the daemon to wake up after the queue is empty,
  78. so it can check for more work
  79. (default: <tt class="docutils literal"><span class="pre">celery.conf.QUEUE_WAKEUP_AFTER</span></tt>).</dd></dl>
  80. <dl class="attribute">
  81. <dt id="celery.worker.TaskDaemon.empty_msg_emit_every">
  82. <tt class="descname">empty_msg_emit_every</tt><a class="headerlink" href="#celery.worker.TaskDaemon.empty_msg_emit_every" title="Permalink to this definition">¶</a></dt>
  83. <dd>How often the daemon emits the <tt class="docutils literal"><span class="pre">Waiting</span> <span class="pre">for</span> <span class="pre">queue</span></tt> message.
  84. If this is <tt class="xref docutils literal"><span class="pre">None</span></tt>, the message will never be logged.
  85. (default: <tt class="docutils literal"><span class="pre">celery.conf.EMPTY_MSG_EMIT_EVERY</span></tt>)</dd></dl>
  86. <dl class="attribute">
  87. <dt id="celery.worker.TaskDaemon.logger">
  88. <tt class="descname">logger</tt><a class="headerlink" href="#celery.worker.TaskDaemon.logger" title="Permalink to this definition">¶</a></dt>
  89. <dd>The <tt class="xref docutils literal"><span class="pre">logging.Logger</span></tt> instance used for logging.</dd></dl>
  90. <dl class="attribute">
  91. <dt id="celery.worker.TaskDaemon.pool">
  92. <tt class="descname">pool</tt><a class="headerlink" href="#celery.worker.TaskDaemon.pool" title="Permalink to this definition">¶</a></dt>
  93. <dt>
  94. <tt class="descname">The :class:`multiprocessing.Pool` instance used.</tt></dt>
  95. <dd></dd></dl>
  96. <dl class="attribute">
  97. <dt id="celery.worker.TaskDaemon.task_consumer">
  98. <tt class="descname">task_consumer</tt><a class="headerlink" href="#celery.worker.TaskDaemon.task_consumer" title="Permalink to this definition">¶</a></dt>
  99. <dd>The <a title="celery.messaging.TaskConsumer" class="reference external" href="celery.messaging.html#celery.messaging.TaskConsumer"><tt class="xref docutils literal"><span class="pre">celery.messaging.TaskConsumer</span></tt></a> instance used.</dd></dl>
  100. <dl class="method">
  101. <dt id="celery.worker.TaskDaemon.connection_diagnostics">
  102. <tt class="descname">connection_diagnostics</tt><big>(</big><big>)</big><a class="headerlink" href="#celery.worker.TaskDaemon.connection_diagnostics" title="Permalink to this definition">¶</a></dt>
  103. <dd>Diagnose the AMQP connection, and reset if necessary.</dd></dl>
  104. <dl class="method">
  105. <dt id="celery.worker.TaskDaemon.execute_next_task">
  106. <tt class="descname">execute_next_task</tt><big>(</big><big>)</big><a class="headerlink" href="#celery.worker.TaskDaemon.execute_next_task" title="Permalink to this definition">¶</a></dt>
  107. <dd><p>Execute the next task on the queue using the multiprocessing
  108. pool.</p>
  109. <p>Catches all exceptions and logs them with level <tt class="docutils literal"><span class="pre">logging.CRITICAL</span></tt>.</p>
  110. </dd></dl>
  111. <dl class="method">
  112. <dt id="celery.worker.TaskDaemon.fetch_next_task">
  113. <tt class="descname">fetch_next_task</tt><big>(</big><big>)</big><a class="headerlink" href="#celery.worker.TaskDaemon.fetch_next_task" title="Permalink to this definition">¶</a></dt>
  114. <dd><p>Fetch the next task from the AMQP broker.</p>
  115. <p>Raises :class`EmptyQueue` exception if there is no messages
  116. waiting on the queue.</p>
  117. <table class="docutils field-list" frame="void" rules="none">
  118. <col class="field-name" />
  119. <col class="field-body" />
  120. <tbody valign="top">
  121. <tr class="field"><th class="field-name">Return type:</th><td class="field-body"><a title="celery.worker.TaskWrapper" class="reference internal" href="#celery.worker.TaskWrapper"><tt class="xref docutils literal"><span class="pre">TaskWrapper</span></tt></a> instance.</td>
  122. </tr>
  123. </tbody>
  124. </table>
  125. </dd></dl>
  126. <dl class="method">
  127. <dt id="celery.worker.TaskDaemon.receive_message">
  128. <tt class="descname">receive_message</tt><big>(</big><big>)</big><a class="headerlink" href="#celery.worker.TaskDaemon.receive_message" title="Permalink to this definition">¶</a></dt>
  129. <dd><p>Receive the next message from the Task consumer queue.</p>
  130. <p>Tries to reset the AMQP connection if not available.
  131. Returns <tt class="xref docutils literal"><span class="pre">None</span></tt> if no message is waiting on the queue.</p>
  132. <table class="docutils field-list" frame="void" rules="none">
  133. <col class="field-name" />
  134. <col class="field-body" />
  135. <tbody valign="top">
  136. <tr class="field"><th class="field-name">Return type:</th><td class="field-body"><tt class="xref docutils literal"><span class="pre">carrot.messaging.Message</span></tt> instance.</td>
  137. </tr>
  138. </tbody>
  139. </table>
  140. </dd></dl>
  141. <dl class="method">
  142. <dt id="celery.worker.TaskDaemon.receive_message_cc">
  143. <tt class="descname">receive_message_cc</tt><big>(</big><big>)</big><a class="headerlink" href="#celery.worker.TaskDaemon.receive_message_cc" title="Permalink to this definition">¶</a></dt>
  144. <dd>UNUSED.</dd></dl>
  145. <dl class="method">
  146. <dt id="celery.worker.TaskDaemon.reset_connection">
  147. <tt class="descname">reset_connection</tt><big>(</big><big>)</big><a class="headerlink" href="#celery.worker.TaskDaemon.reset_connection" title="Permalink to this definition">¶</a></dt>
  148. <dd>Reset the AMQP connection, and reinitialize the
  149. <a title="celery.messaging.TaskConsumer" class="reference external" href="celery.messaging.html#celery.messaging.TaskConsumer"><tt class="xref docutils literal"><span class="pre">celery.messaging.TaskConsumer</span></tt></a> instance.</dd></dl>
  150. <dl class="method">
  151. <dt id="celery.worker.TaskDaemon.run">
  152. <tt class="descname">run</tt><big>(</big><big>)</big><a class="headerlink" href="#celery.worker.TaskDaemon.run" title="Permalink to this definition">¶</a></dt>
  153. <dd>The worker server&#8217;s main loop.</dd></dl>
  154. <dl class="method">
  155. <dt id="celery.worker.TaskDaemon.run_periodic_tasks">
  156. <tt class="descname">run_periodic_tasks</tt><big>(</big><big>)</big><a class="headerlink" href="#celery.worker.TaskDaemon.run_periodic_tasks" title="Permalink to this definition">¶</a></dt>
  157. <dd><p>Schedule all waiting periodic tasks for execution.</p>
  158. <table class="docutils field-list" frame="void" rules="none">
  159. <col class="field-name" />
  160. <col class="field-body" />
  161. <tbody valign="top">
  162. <tr class="field"><th class="field-name">Return type:</th><td class="field-body">list of <tt class="xref docutils literal"><span class="pre">celery.models.PeriodicTaskMeta</span></tt> objects.</td>
  163. </tr>
  164. </tbody>
  165. </table>
  166. </dd></dl>
  167. <dl class="method">
  168. <dt id="celery.worker.TaskDaemon.schedule_retry_tasks">
  169. <tt class="descname">schedule_retry_tasks</tt><big>(</big><big>)</big><a class="headerlink" href="#celery.worker.TaskDaemon.schedule_retry_tasks" title="Permalink to this definition">¶</a></dt>
  170. <dd>Reschedule all requeued tasks waiting for retry.</dd></dl>
  171. </dd></dl>
  172. <dl class="class">
  173. <dt id="celery.worker.TaskWrapper">
  174. <em class="property">
  175. class </em><tt class="descclassname">celery.worker.</tt><tt class="descname">TaskWrapper</tt><big>(</big><em>task_name</em>, <em>task_id</em>, <em>task_func</em>, <em>args</em>, <em>kwargs</em><big>)</big><a class="headerlink" href="#celery.worker.TaskWrapper" title="Permalink to this definition">¶</a></dt>
  176. <dd><p>Class defining a task to be run.</p>
  177. <dl class="method">
  178. <dt id="celery.worker.TaskWrapper.execute">
  179. <tt class="descname">execute</tt><big>(</big><em>loglevel</em>, <em>logfile</em><big>)</big><a class="headerlink" href="#celery.worker.TaskWrapper.execute" title="Permalink to this definition">¶</a></dt>
  180. <dd>Execute the task in a <tt class="docutils literal"><span class="pre">jail()</span></tt> and store its result and status
  181. in the task meta backend.</dd></dl>
  182. <dl class="method">
  183. <dt id="celery.worker.TaskWrapper.execute_using_pool">
  184. <tt class="descname">execute_using_pool</tt><big>(</big><em>pool</em>, <em>loglevel</em>, <em>logfile</em><big>)</big><a class="headerlink" href="#celery.worker.TaskWrapper.execute_using_pool" title="Permalink to this definition">¶</a></dt>
  185. <dd><p>Like <tt class="docutils literal"><span class="pre">execute</span></tt>, but using the <tt class="docutils literal"><span class="pre">multiprocessing</span></tt> pool.</p>
  186. <table class="docutils field-list" frame="void" rules="none">
  187. <col class="field-name" />
  188. <col class="field-body" />
  189. <tbody valign="top">
  190. <tr class="field"><th class="field-name">Return type:</th><td class="field-body"><tt class="xref docutils literal"><span class="pre">multiprocessing.AsyncResult</span></tt> instance.</td>
  191. </tr>
  192. </tbody>
  193. </table>
  194. </dd></dl>
  195. <dl class="method">
  196. <dt id="celery.worker.TaskWrapper.extend_kwargs_with_logging">
  197. <tt class="descname">extend_kwargs_with_logging</tt><big>(</big><em>loglevel</em>, <em>logfile</em><big>)</big><a class="headerlink" href="#celery.worker.TaskWrapper.extend_kwargs_with_logging" title="Permalink to this definition">¶</a></dt>
  198. <dd><p>Extend the tasks keyword arguments with standard task arguments.</p>
  199. <p>These are <tt class="docutils literal"><span class="pre">logfile</span></tt>, <tt class="docutils literal"><span class="pre">loglevel</span></tt>, <tt class="docutils literal"><span class="pre">task_id</span></tt> and <tt class="docutils literal"><span class="pre">task_name</span></tt>.</p>
  200. </dd></dl>
  201. <dl class="classmethod">
  202. <dt id="celery.worker.TaskWrapper.from_message">
  203. <em class="property">
  204. classmethod </em><tt class="descname">from_message</tt><big>(</big><em>message</em><big>)</big><a class="headerlink" href="#celery.worker.TaskWrapper.from_message" title="Permalink to this definition">¶</a></dt>
  205. <dd><p>Create a TaskWrapper from a message returned by
  206. <a title="celery.messaging.TaskConsumer" class="reference external" href="celery.messaging.html#celery.messaging.TaskConsumer"><tt class="xref docutils literal"><span class="pre">celery.messaging.TaskConsumer</span></tt></a>.</p>
  207. <p>If the message is not a proper task it raises
  208. <a title="celery.worker.UnknownTask" class="reference internal" href="#celery.worker.UnknownTask"><tt class="xref docutils literal"><span class="pre">UnknownTask</span></tt></a> exception.</p>
  209. <table class="docutils field-list" frame="void" rules="none">
  210. <col class="field-name" />
  211. <col class="field-body" />
  212. <tbody valign="top">
  213. <tr class="field"><th class="field-name">Return type:</th><td class="field-body"><a title="celery.worker.TaskWrapper" class="reference internal" href="#celery.worker.TaskWrapper"><tt class="xref docutils literal"><span class="pre">TaskWrapper</span></tt></a> instance.</td>
  214. </tr>
  215. </tbody>
  216. </table>
  217. </dd></dl>
  218. </dd></dl>
  219. <dl class="exception">
  220. <dt id="celery.worker.UnknownTask">
  221. <em class="property">
  222. exception </em><tt class="descclassname">celery.worker.</tt><tt class="descname">UnknownTask</tt><a class="headerlink" href="#celery.worker.UnknownTask" title="Permalink to this definition">¶</a></dt>
  223. <dd>Got an unknown task in the queue. The message is requeued and
  224. ignored.</dd></dl>
  225. <dl class="function">
  226. <dt id="celery.worker.jail">
  227. <tt class="descclassname">celery.worker.</tt><tt class="descname">jail</tt><big>(</big><em>task_id</em>, <em>callable_</em>, <em>args</em>, <em>kwargs</em><big>)</big><a class="headerlink" href="#celery.worker.jail" title="Permalink to this definition">¶</a></dt>
  228. <dd><p>Wraps the task in a jail which saves the status and result
  229. of the task execution to the task meta backend.</p>
  230. <p>If the call results in an exception, it saves the exception as the task
  231. result, and sets the task status to <tt class="docutils literal"><span class="pre">FAILURE</span></tt>.</p>
  232. <p>If the call was successful, it saves the result to the task result
  233. backend, and sets the task status to <tt class="docutils literal"><span class="pre">DONE</span></tt>.</p>
  234. </dd></dl>
  235. </div>
  236. </div>
  237. </div>
  238. </div>
  239. <div class="sphinxsidebar">
  240. <div class="sphinxsidebarwrapper">
  241. <h4>Previous topic</h4>
  242. <p class="topless"><a href="celery.discovery.html"
  243. title="previous chapter">Task Discovery - celery.discovery</a></p>
  244. <h4>Next topic</h4>
  245. <p class="topless"><a href="celery.backends.html"
  246. title="next chapter">Backends - celery.backends</a></p>
  247. <h3>This Page</h3>
  248. <ul class="this-page-menu">
  249. <li><a href="../sources/reference/celery.worker.txt"
  250. rel="nofollow">Show Source</a></li>
  251. </ul>
  252. <div id="searchbox" style="display: none">
  253. <h3>Quick search</h3>
  254. <form class="search" action="../search.html" method="get">
  255. <input type="text" name="q" size="18" />
  256. <input type="submit" value="Go" />
  257. <input type="hidden" name="check_keywords" value="yes" />
  258. <input type="hidden" name="area" value="default" />
  259. </form>
  260. <p class="searchtip" style="font-size: 90%">
  261. Enter search terms or a module, class or function name.
  262. </p>
  263. </div>
  264. <script type="text/javascript">$('#searchbox').show(0);</script>
  265. </div>
  266. </div>
  267. <div class="clearer"></div>
  268. </div>
  269. <div class="related">
  270. <h3>Navigation</h3>
  271. <ul>
  272. <li class="right" style="margin-right: 10px">
  273. <a href="../genindex.html" title="General Index"
  274. >index</a></li>
  275. <li class="right" >
  276. <a href="../modindex.html" title="Global Module Index"
  277. >modules</a> |</li>
  278. <li class="right" >
  279. <a href="celery.backends.html" title="Backends - celery.backends"
  280. >next</a> |</li>
  281. <li class="right" >
  282. <a href="celery.discovery.html" title="Task Discovery - celery.discovery"
  283. >previous</a> |</li>
  284. <li><a href="../index.html">Celery v0.1.14 documentation</a> &raquo;</li>
  285. </ul>
  286. </div>
  287. <div class="footer">
  288. &copy; Copyright 2009, Ask Solem.
  289. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.1.
  290. </div>
  291. </body>
  292. </html>