celery.task.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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>Task Information and Utilities - celery.task &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="up" title="Module API Reference" href="index.html" />
  22. <link rel="next" title="Task Registry - celery.registry" href="celery.registry.html" />
  23. <link rel="prev" title="Task Result - celery.result" href="celery.result.html" />
  24. </head>
  25. <body>
  26. <div class="related">
  27. <h3>Navigation</h3>
  28. <ul>
  29. <li class="right" style="margin-right: 10px">
  30. <a href="../genindex.html" title="General Index"
  31. accesskey="I">index</a></li>
  32. <li class="right" >
  33. <a href="../modindex.html" title="Global Module Index"
  34. accesskey="M">modules</a> |</li>
  35. <li class="right" >
  36. <a href="celery.registry.html" title="Task Registry - celery.registry"
  37. accesskey="N">next</a> |</li>
  38. <li class="right" >
  39. <a href="celery.result.html" title="Task Result - celery.result"
  40. accesskey="P">previous</a> |</li>
  41. <li><a href="../index.html">Celery v0.7.0 (unstable) documentation</a> &raquo;</li>
  42. <li><a href="index.html" accesskey="U">Module API Reference</a> &raquo;</li>
  43. </ul>
  44. </div>
  45. <div class="document">
  46. <div class="documentwrapper">
  47. <div class="bodywrapper">
  48. <div class="body">
  49. <div class="section" id="module-celery.task">
  50. <h1>Task Information and Utilities - celery.task<a class="headerlink" href="#module-celery.task" title="Permalink to this headline">¶</a></h1>
  51. <p>Working with tasks and task sets.</p>
  52. <dl class="function">
  53. <dt id="celery.task.discard_all">
  54. <tt class="descclassname">celery.task.</tt><tt class="descname">discard_all</tt><big>(</big><em>connect_timeout=4</em><big>)</big><a class="headerlink" href="#celery.task.discard_all" title="Permalink to this definition">¶</a></dt>
  55. <dd><p>Discard all waiting tasks.</p>
  56. <p>This will ignore all tasks waiting for execution, and they will
  57. be deleted from the messaging server.</p>
  58. <table class="docutils field-list" frame="void" rules="none">
  59. <col class="field-name" />
  60. <col class="field-body" />
  61. <tbody valign="top">
  62. <tr class="field"><th class="field-name">Returns:</th><td class="field-body">the number of tasks discarded.</td>
  63. </tr>
  64. <tr class="field"><th class="field-name">Return type:</th><td class="field-body">int</td>
  65. </tr>
  66. </tbody>
  67. </table>
  68. </dd></dl>
  69. <dl class="function">
  70. <dt id="celery.task.dmap">
  71. <tt class="descclassname">celery.task.</tt><tt class="descname">dmap</tt><big>(</big><em>func</em>, <em>args</em>, <em>timeout=None</em><big>)</big><a class="headerlink" href="#celery.task.dmap" title="Permalink to this definition">¶</a></dt>
  72. <dd><p>Distribute processing of the arguments and collect the results.</p>
  73. <p>Example</p>
  74. <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">dmap</span>
  75. <span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">operator</span>
  76. <span class="gp">&gt;&gt;&gt; </span><span class="n">dmap</span><span class="p">(</span><span class="n">operator</span><span class="o">.</span><span class="n">add</span><span class="p">,</span> <span class="p">[[</span><span class="mf">2</span><span class="p">,</span> <span class="mf">2</span><span class="p">],</span> <span class="p">[</span><span class="mf">4</span><span class="p">,</span> <span class="mf">4</span><span class="p">],</span> <span class="p">[</span><span class="mf">8</span><span class="p">,</span> <span class="mf">8</span><span class="p">]])</span>
  77. <span class="go">[4, 8, 16]</span>
  78. </pre></div>
  79. </div>
  80. </dd></dl>
  81. <dl class="function">
  82. <dt id="celery.task.dmap_async">
  83. <tt class="descclassname">celery.task.</tt><tt class="descname">dmap_async</tt><big>(</big><em>func</em>, <em>args</em>, <em>timeout=None</em><big>)</big><a class="headerlink" href="#celery.task.dmap_async" title="Permalink to this definition">¶</a></dt>
  84. <dd><p>Distribute processing of the arguments and collect the results
  85. asynchronously.</p>
  86. <table class="docutils field-list" frame="void" rules="none">
  87. <col class="field-name" />
  88. <col class="field-body" />
  89. <tbody valign="top">
  90. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><a title="celery.result.AsyncResult" class="reference external" href="celery.result.html#celery.result.AsyncResult"><tt class="xref docutils literal"><span class="pre">celery.result.AsyncResult</span></tt></a> object.</td>
  91. </tr>
  92. </tbody>
  93. </table>
  94. <p>Example</p>
  95. <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">dmap_async</span>
  96. <span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">operator</span>
  97. <span class="gp">&gt;&gt;&gt; </span><span class="n">presult</span> <span class="o">=</span> <span class="n">dmap_async</span><span class="p">(</span><span class="n">operator</span><span class="o">.</span><span class="n">add</span><span class="p">,</span> <span class="p">[[</span><span class="mf">2</span><span class="p">,</span> <span class="mf">2</span><span class="p">],</span> <span class="p">[</span><span class="mf">4</span><span class="p">,</span> <span class="mf">4</span><span class="p">],</span> <span class="p">[</span><span class="mf">8</span><span class="p">,</span> <span class="mf">8</span><span class="p">]])</span>
  98. <span class="gp">&gt;&gt;&gt; </span><span class="n">presult</span>
  99. <span class="go">&lt;AsyncResult: 373550e8-b9a0-4666-bc61-ace01fa4f91d&gt;</span>
  100. <span class="gp">&gt;&gt;&gt; </span><span class="n">presult</span><span class="o">.</span><span class="n">status</span>
  101. <span class="go">&#39;DONE&#39;</span>
  102. <span class="gp">&gt;&gt;&gt; </span><span class="n">presult</span><span class="o">.</span><span class="n">result</span>
  103. <span class="go">[4, 8, 16]</span>
  104. </pre></div>
  105. </div>
  106. </dd></dl>
  107. <dl class="function">
  108. <dt id="celery.task.execute_remote">
  109. <tt class="descclassname">celery.task.</tt><tt class="descname">execute_remote</tt><big>(</big><em>func</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#celery.task.execute_remote" title="Permalink to this definition">¶</a></dt>
  110. <dd><p>Execute arbitrary function/object remotely.</p>
  111. <table class="docutils field-list" frame="void" rules="none">
  112. <col class="field-name" />
  113. <col class="field-body" />
  114. <tbody valign="top">
  115. <tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  116. <li><em>func</em> &#8211; A callable function or object.</li>
  117. <li><em>*args</em> &#8211; Positional arguments to apply to the function.</li>
  118. <li><em>**kwargs</em> &#8211; Keyword arguments to apply to the function.</li>
  119. </ul>
  120. </td>
  121. </tr>
  122. </tbody>
  123. </table>
  124. <p>The object must be picklable, so you can&#8217;t use lambdas or functions
  125. defined in the REPL (the objects must have an associated module).</p>
  126. <table class="docutils field-list" frame="void" rules="none">
  127. <col class="field-name" />
  128. <col class="field-body" />
  129. <tbody valign="top">
  130. <tr class="field"><th class="field-name">Returns:</th><td class="field-body">class:<cite>celery.result.AsyncResult</cite>.</td>
  131. </tr>
  132. </tbody>
  133. </table>
  134. </dd></dl>
  135. <dl class="function">
  136. <dt id="celery.task.is_done">
  137. <tt class="descclassname">celery.task.</tt><tt class="descname">is_done</tt><big>(</big><em>task_id</em><big>)</big><a class="headerlink" href="#celery.task.is_done" title="Permalink to this definition">¶</a></dt>
  138. <dd><p>Returns <tt class="xref docutils literal"><span class="pre">True</span></tt> if task with <tt class="docutils literal"><span class="pre">task_id</span></tt> has been executed.</p>
  139. <table class="docutils field-list" frame="void" rules="none">
  140. <col class="field-name" />
  141. <col class="field-body" />
  142. <tbody valign="top">
  143. <tr class="field"><th class="field-name">Return type:</th><td class="field-body">bool</td>
  144. </tr>
  145. </tbody>
  146. </table>
  147. </dd></dl>
  148. <dl class="function">
  149. <dt id="celery.task.ping">
  150. <tt class="descclassname">celery.task.</tt><tt class="descname">ping</tt><big>(</big><big>)</big><a class="headerlink" href="#celery.task.ping" title="Permalink to this definition">¶</a></dt>
  151. <dd><p>Test if the server is alive.</p>
  152. <p>Example:</p>
  153. <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">ping</span>
  154. <span class="gp">&gt;&gt;&gt; </span><span class="n">ping</span><span class="p">()</span>
  155. <span class="go">&#39;pong&#39;</span>
  156. </pre></div>
  157. </div>
  158. </dd></dl>
  159. </div>
  160. </div>
  161. </div>
  162. </div>
  163. <div class="sphinxsidebar">
  164. <div class="sphinxsidebarwrapper">
  165. <h4>Previous topic</h4>
  166. <p class="topless"><a href="celery.result.html"
  167. title="previous chapter">Task Result - celery.result</a></p>
  168. <h4>Next topic</h4>
  169. <p class="topless"><a href="celery.registry.html"
  170. title="next chapter">Task Registry - celery.registry</a></p>
  171. <h3>This Page</h3>
  172. <ul class="this-page-menu">
  173. <li><a href="../sources/reference/celery.task.txt"
  174. rel="nofollow">Show Source</a></li>
  175. </ul>
  176. <div id="searchbox" style="display: none">
  177. <h3>Quick search</h3>
  178. <form class="search" action="../search.html" method="get">
  179. <input type="text" name="q" size="18" />
  180. <input type="submit" value="Go" />
  181. <input type="hidden" name="check_keywords" value="yes" />
  182. <input type="hidden" name="area" value="default" />
  183. </form>
  184. <p class="searchtip" style="font-size: 90%">
  185. Enter search terms or a module, class or function name.
  186. </p>
  187. </div>
  188. <script type="text/javascript">$('#searchbox').show(0);</script>
  189. </div>
  190. </div>
  191. <div class="clearer"></div>
  192. </div>
  193. <div class="related">
  194. <h3>Navigation</h3>
  195. <ul>
  196. <li class="right" style="margin-right: 10px">
  197. <a href="../genindex.html" title="General Index"
  198. >index</a></li>
  199. <li class="right" >
  200. <a href="../modindex.html" title="Global Module Index"
  201. >modules</a> |</li>
  202. <li class="right" >
  203. <a href="celery.registry.html" title="Task Registry - celery.registry"
  204. >next</a> |</li>
  205. <li class="right" >
  206. <a href="celery.result.html" title="Task Result - celery.result"
  207. >previous</a> |</li>
  208. <li><a href="../index.html">Celery v0.7.0 (unstable) documentation</a> &raquo;</li>
  209. <li><a href="index.html" >Module API Reference</a> &raquo;</li>
  210. </ul>
  211. </div>
  212. <div class="footer">
  213. &copy; Copyright 2009, Ask Solem.
  214. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.2.
  215. </div>
  216. </body>
  217. </html>