celery.task.html 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  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>Tasks - celery.task &mdash; Celery v0.3.10 (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.10 (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.10 (unstable) documentation" href="../index.html" />
  21. <link rel="up" title="Module API Reference" href="index.html" />
  22. <link rel="next" title="Task Result - celery.result" href="celery.result.html" />
  23. <link rel="prev" title="Module API Reference" href="index.html" />
  24. </head>
  25. <body>
  26. <div class="header-wrapper">
  27. <div class="header">
  28. <h1><a href="../index.html">Celery v0.3.10 (unstable) documentation</a></h1>
  29. <div class="rel">
  30. <a href="../genindex.html" title="General Index"
  31. accesskey="I">index</a> |
  32. <a href="../modindex.html" title="Global Module Index"
  33. accesskey="M">modules</a> |
  34. <a href="celery.result.html" title="Task Result - celery.result"
  35. accesskey="N">next</a> |
  36. <a href="index.html" title="Module API Reference"
  37. accesskey="P">previous</a>
  38. </div>
  39. </div>
  40. </div>
  41. <div class="content-wrapper">
  42. <div class="content">
  43. <div class="document">
  44. <div class="documentwrapper">
  45. <div class="bodywrapper">
  46. <div class="body">
  47. <div class="section" id="module-celery.task">
  48. <h1>Tasks - celery.task<a class="headerlink" href="#module-celery.task" title="Permalink to this headline">¶</a></h1>
  49. <p>Working with tasks and task sets.</p>
  50. <dl class="class">
  51. <dt id="celery.task.AsynchronousMapTask">
  52. <em class="property">
  53. class </em><tt class="descclassname">celery.task.</tt><tt class="descname">AsynchronousMapTask</tt><a class="headerlink" href="#celery.task.AsynchronousMapTask" title="Permalink to this definition">¶</a></dt>
  54. <dd><p>Task used internally by <a title="celery.task.dmap_async" class="reference internal" href="#celery.task.dmap_async"><tt class="xref docutils literal"><span class="pre">dmap_async()</span></tt></a> and
  55. <a title="celery.task.TaskSet.map_async" class="reference internal" href="#celery.task.TaskSet.map_async"><tt class="xref docutils literal"><span class="pre">TaskSet.map_async()</span></tt></a>.</p>
  56. <dl class="method">
  57. <dt id="celery.task.AsynchronousMapTask.run">
  58. <tt class="descname">run</tt><big>(</big><em>serfunc</em>, <em>args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#celery.task.AsynchronousMapTask.run" title="Permalink to this definition">¶</a></dt>
  59. <dd>The method run by <tt class="docutils literal"><span class="pre">celeryd</span></tt>.</dd></dl>
  60. </dd></dl>
  61. <dl class="class">
  62. <dt id="celery.task.DeleteExpiredTaskMetaTask">
  63. <em class="property">
  64. class </em><tt class="descclassname">celery.task.</tt><tt class="descname">DeleteExpiredTaskMetaTask</tt><a class="headerlink" href="#celery.task.DeleteExpiredTaskMetaTask" title="Permalink to this definition">¶</a></dt>
  65. <dd><p>A periodic task that deletes expired task metadata every day.</p>
  66. <p>This runs the current backend&#8217;s
  67. <a title="celery.backends.base.BaseBackend.cleanup" class="reference external" href="celery.backends.base.html#celery.backends.base.BaseBackend.cleanup"><tt class="xref docutils literal"><span class="pre">celery.backends.base.BaseBackend.cleanup()</span></tt></a> method.</p>
  68. <dl class="method">
  69. <dt id="celery.task.DeleteExpiredTaskMetaTask.run">
  70. <tt class="descname">run</tt><big>(</big><em>**kwargs</em><big>)</big><a class="headerlink" href="#celery.task.DeleteExpiredTaskMetaTask.run" title="Permalink to this definition">¶</a></dt>
  71. <dd>The method run by <tt class="docutils literal"><span class="pre">celeryd</span></tt>.</dd></dl>
  72. </dd></dl>
  73. <dl class="class">
  74. <dt id="celery.task.ExecuteRemoteTask">
  75. <em class="property">
  76. class </em><tt class="descclassname">celery.task.</tt><tt class="descname">ExecuteRemoteTask</tt><a class="headerlink" href="#celery.task.ExecuteRemoteTask" title="Permalink to this definition">¶</a></dt>
  77. <dd><p>Execute an arbitrary function or object.</p>
  78. <p><em>Note</em> You probably want <a title="celery.task.execute_remote" class="reference internal" href="#celery.task.execute_remote"><tt class="xref docutils literal"><span class="pre">execute_remote()</span></tt></a> instead, which this
  79. is an internal component of.</p>
  80. <p>The object must be pickleable, so you can&#8217;t use lambdas or functions
  81. defined in the REPL (that is the python shell, or <tt class="docutils literal"><span class="pre">ipython</span></tt>).</p>
  82. <dl class="method">
  83. <dt id="celery.task.ExecuteRemoteTask.run">
  84. <tt class="descname">run</tt><big>(</big><em>ser_callable</em>, <em>fargs</em>, <em>fkwargs</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#celery.task.ExecuteRemoteTask.run" title="Permalink to this definition">¶</a></dt>
  85. <dd><table class="docutils field-list" frame="void" rules="none">
  86. <col class="field-name" />
  87. <col class="field-body" />
  88. <tbody valign="top">
  89. <tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  90. <li><em>ser_callable</em> &#8211; A pickled function or callable object.</li>
  91. <li><em>fargs</em> &#8211; Positional arguments to apply to the function.</li>
  92. <li><em>fkwargs</em> &#8211; Keyword arguments to apply to the function.</li>
  93. </ul>
  94. </td>
  95. </tr>
  96. </tbody>
  97. </table>
  98. </dd></dl>
  99. </dd></dl>
  100. <dl class="class">
  101. <dt id="celery.task.PeriodicTask">
  102. <em class="property">
  103. class </em><tt class="descclassname">celery.task.</tt><tt class="descname">PeriodicTask</tt><a class="headerlink" href="#celery.task.PeriodicTask" title="Permalink to this definition">¶</a></dt>
  104. <dd><p>A periodic task is a task that behaves like a <em>cron</em> job.</p>
  105. <dl class="attribute">
  106. <dt id="celery.task.PeriodicTask.run_every">
  107. <tt class="descname">run_every</tt><a class="headerlink" href="#celery.task.PeriodicTask.run_every" title="Permalink to this definition">¶</a></dt>
  108. <dd><em>REQUIRED</em> Defines how often the task is run (its interval),
  109. it can be either a <tt class="xref docutils literal"><span class="pre">datetime.timedelta</span></tt> object or an
  110. integer specifying the time in seconds.</dd></dl>
  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" colspan="2">Raises NotImplementedError:</th></tr>
  116. <tr><td>&nbsp;</td><td class="field-body">if the <a title="celery.task.PeriodicTask.run_every" class="reference internal" href="#celery.task.PeriodicTask.run_every"><tt class="xref docutils literal"><span class="pre">run_every</span></tt></a> attribute is
  117. not defined.</td>
  118. </tr>
  119. </tbody>
  120. </table>
  121. <p>You have to register the periodic task in the task registry.</p>
  122. <p>Example</p>
  123. <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">tasks</span><span class="p">,</span> <span class="n">PeriodicTask</span>
  124. <span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">timedelta</span>
  125. <span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">MyPeriodicTask</span><span class="p">(</span><span class="n">PeriodicTask</span><span class="p">):</span>
  126. <span class="gp">... </span> <span class="n">name</span> <span class="o">=</span> <span class="s">&quot;my_periodic_task&quot;</span>
  127. <span class="gp">... </span> <span class="n">run_every</span> <span class="o">=</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">seconds</span><span class="o">=</span><span class="mf">30</span><span class="p">)</span>
  128. <span class="gp">...</span>
  129. <span class="gp">... </span> <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="o">**</span><span class="n">kwargs</span><span class="p">):</span>
  130. <span class="gp">... </span> <span class="n">logger</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_logger</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
  131. <span class="gp">... </span> <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&quot;Running MyPeriodicTask&quot;</span><span class="p">)</span>
  132. <span class="gp">&gt;&gt;&gt; </span><span class="n">tasks</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">MyPeriodicTask</span><span class="p">)</span>
  133. </pre></div>
  134. </div>
  135. </dd></dl>
  136. <dl class="class">
  137. <dt id="celery.task.PingTask">
  138. <em class="property">
  139. class </em><tt class="descclassname">celery.task.</tt><tt class="descname">PingTask</tt><a class="headerlink" href="#celery.task.PingTask" title="Permalink to this definition">¶</a></dt>
  140. <dd><p>The task used by <a title="celery.task.ping" class="reference internal" href="#celery.task.ping"><tt class="xref docutils literal"><span class="pre">ping()</span></tt></a>.</p>
  141. <dl class="method">
  142. <dt id="celery.task.PingTask.run">
  143. <tt class="descname">run</tt><big>(</big><em>**kwargs</em><big>)</big><a class="headerlink" href="#celery.task.PingTask.run" title="Permalink to this definition">¶</a></dt>
  144. <dd><table class="docutils field-list" frame="void" rules="none">
  145. <col class="field-name" />
  146. <col class="field-body" />
  147. <tbody valign="top">
  148. <tr class="field"><th class="field-name">Returns:</th><td class="field-body">the string <tt class="docutils literal"><span class="pre">&quot;pong&quot;</span></tt>.</td>
  149. </tr>
  150. </tbody>
  151. </table>
  152. </dd></dl>
  153. </dd></dl>
  154. <dl class="class">
  155. <dt id="celery.task.Task">
  156. <em class="property">
  157. class </em><tt class="descclassname">celery.task.</tt><tt class="descname">Task</tt><a class="headerlink" href="#celery.task.Task" title="Permalink to this definition">¶</a></dt>
  158. <dd><p>A task that can be delayed for execution by the <tt class="docutils literal"><span class="pre">celery</span></tt> daemon.</p>
  159. <p>All subclasses of <a title="celery.task.Task" class="reference internal" href="#celery.task.Task"><tt class="xref docutils literal"><span class="pre">Task</span></tt></a> must define the <a title="celery.task.Task.run" class="reference internal" href="#celery.task.Task.run"><tt class="xref docutils literal"><span class="pre">run()</span></tt></a> method,
  160. which is the actual method the <tt class="docutils literal"><span class="pre">celery</span></tt> daemon executes.</p>
  161. <p>The <a title="celery.task.Task.run" class="reference internal" href="#celery.task.Task.run"><tt class="xref docutils literal"><span class="pre">run()</span></tt></a> method supports both positional, and keyword arguments.</p>
  162. <dl class="attribute">
  163. <dt id="celery.task.Task.name">
  164. <tt class="descname">name</tt><a class="headerlink" href="#celery.task.Task.name" title="Permalink to this definition">¶</a></dt>
  165. <dd><em>REQUIRED</em> All subclasses of <a title="celery.task.Task" class="reference internal" href="#celery.task.Task"><tt class="xref docutils literal"><span class="pre">Task</span></tt></a> has to define the
  166. <a title="celery.task.Task.name" class="reference internal" href="#celery.task.Task.name"><tt class="xref docutils literal"><span class="pre">name</span></tt></a> attribute. This is the name of the task, registered
  167. in the task registry, and passed to <a title="celery.task.delay_task" class="reference internal" href="#celery.task.delay_task"><tt class="xref docutils literal"><span class="pre">delay_task()</span></tt></a>.</dd></dl>
  168. <dl class="attribute">
  169. <dt id="celery.task.Task.type">
  170. <tt class="descname">type</tt><a class="headerlink" href="#celery.task.Task.type" title="Permalink to this definition">¶</a></dt>
  171. <dd>The type of task, currently this can be <tt class="docutils literal"><span class="pre">regular</span></tt>, or <tt class="docutils literal"><span class="pre">periodic</span></tt>,
  172. however if you want a periodic task, you should subclass
  173. <a title="celery.task.PeriodicTask" class="reference internal" href="#celery.task.PeriodicTask"><tt class="xref docutils literal"><span class="pre">PeriodicTask</span></tt></a> instead.</dd></dl>
  174. <table class="docutils field-list" frame="void" rules="none">
  175. <col class="field-name" />
  176. <col class="field-body" />
  177. <tbody valign="top">
  178. <tr class="field"><th class="field-name" colspan="2">Raises NotImplementedError:</th></tr>
  179. <tr><td>&nbsp;</td><td class="field-body">if the <a title="celery.task.Task.name" class="reference internal" href="#celery.task.Task.name"><tt class="xref docutils literal"><span class="pre">name</span></tt></a> attribute is not set.</td>
  180. </tr>
  181. </tbody>
  182. </table>
  183. <p>The resulting class is callable, which if called will apply the
  184. <a title="celery.task.Task.run" class="reference internal" href="#celery.task.Task.run"><tt class="xref docutils literal"><span class="pre">run()</span></tt></a> method.</p>
  185. <p>Examples</p>
  186. <p>This is a simple task just logging a message,</p>
  187. <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">tasks</span><span class="p">,</span> <span class="n">Task</span>
  188. <span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">MyTask</span><span class="p">(</span><span class="n">Task</span><span class="p">):</span>
  189. <span class="gp">... </span> <span class="n">name</span> <span class="o">=</span> <span class="s">&quot;mytask&quot;</span>
  190. <span class="gp">...</span>
  191. <span class="gp">... </span> <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">some_arg</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
  192. <span class="gp">... </span> <span class="n">logger</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_logger</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
  193. <span class="gp">... </span> <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&quot;Running MyTask with arg some_arg=</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span>
  194. <span class="gp">... </span> <span class="n">some_arg</span><span class="p">))</span>
  195. <span class="gp">... </span> <span class="k">return</span> <span class="mf">42</span>
  196. <span class="gp">... </span><span class="n">tasks</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">MyTask</span><span class="p">)</span>
  197. </pre></div>
  198. </div>
  199. <p>You can delay the task using the classmethod <a title="celery.task.Task.delay" class="reference internal" href="#celery.task.Task.delay"><tt class="xref docutils literal"><span class="pre">delay()</span></tt></a>...</p>
  200. <div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">result</span> <span class="o">=</span> <span class="n">MyTask</span><span class="o">.</span><span class="n">delay</span><span class="p">(</span><span class="n">some_arg</span><span class="o">=</span><span class="s">&quot;foo&quot;</span><span class="p">)</span>
  201. <span class="gp">&gt;&gt;&gt; </span><span class="n">result</span><span class="o">.</span><span class="n">status</span> <span class="c"># after some time</span>
  202. <span class="go">&#39;DONE&#39;</span>
  203. <span class="gp">&gt;&gt;&gt; </span><span class="n">result</span><span class="o">.</span><span class="n">result</span>
  204. <span class="go">42</span>
  205. </pre></div>
  206. </div>
  207. <p>...or using the <a title="celery.task.delay_task" class="reference internal" href="#celery.task.delay_task"><tt class="xref docutils literal"><span class="pre">delay_task()</span></tt></a> function, by passing the name of
  208. the task.</p>
  209. <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">delay_task</span>
  210. <span class="gp">&gt;&gt;&gt; </span><span class="n">result</span> <span class="o">=</span> <span class="n">delay_task</span><span class="p">(</span><span class="n">MyTask</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">some_arg</span><span class="o">=</span><span class="s">&quot;foo&quot;</span><span class="p">)</span>
  211. </pre></div>
  212. </div>
  213. <dl class="classmethod">
  214. <dt id="celery.task.Task.apply_async">
  215. <em class="property">
  216. classmethod </em><tt class="descname">apply_async</tt><big>(</big><em>args=None</em>, <em>kwargs=None</em>, <em>**options</em><big>)</big><a class="headerlink" href="#celery.task.Task.apply_async" title="Permalink to this definition">¶</a></dt>
  217. <dd><p>Delay this task for execution by the <tt class="docutils literal"><span class="pre">celery</span></tt> daemon(s).</p>
  218. <table class="docutils field-list" frame="void" rules="none">
  219. <col class="field-name" />
  220. <col class="field-body" />
  221. <tbody valign="top">
  222. <tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  223. <li><em>args</em> &#8211; positional arguments passed on to the task.</li>
  224. <li><em>kwargs</em> &#8211; keyword arguments passed on to the task.</li>
  225. </ul>
  226. </td>
  227. </tr>
  228. <tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last"><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></p>
  229. </td>
  230. </tr>
  231. </tbody>
  232. </table>
  233. <p>See <a title="celery.task.apply_async" class="reference internal" href="#celery.task.apply_async"><tt class="xref docutils literal"><span class="pre">apply_async()</span></tt></a>.</p>
  234. </dd></dl>
  235. <dl class="classmethod">
  236. <dt id="celery.task.Task.delay">
  237. <em class="property">
  238. classmethod </em><tt class="descname">delay</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#celery.task.Task.delay" title="Permalink to this definition">¶</a></dt>
  239. <dd><p>Delay this task for execution by the <tt class="docutils literal"><span class="pre">celery</span></tt> daemon(s).</p>
  240. <table class="docutils field-list" frame="void" rules="none">
  241. <col class="field-name" />
  242. <col class="field-body" />
  243. <tbody valign="top">
  244. <tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  245. <li><em>*args</em> &#8211; positional arguments passed on to the task.</li>
  246. <li><em>**kwargs</em> &#8211; keyword arguments passed on to the task.</li>
  247. </ul>
  248. </td>
  249. </tr>
  250. <tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last"><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></p>
  251. </td>
  252. </tr>
  253. </tbody>
  254. </table>
  255. <p>See <a title="celery.task.delay_task" class="reference internal" href="#celery.task.delay_task"><tt class="xref docutils literal"><span class="pre">delay_task()</span></tt></a>.</p>
  256. </dd></dl>
  257. <dl class="method">
  258. <dt id="celery.task.Task.get_consumer">
  259. <tt class="descname">get_consumer</tt><big>(</big><big>)</big><a class="headerlink" href="#celery.task.Task.get_consumer" title="Permalink to this definition">¶</a></dt>
  260. <dd><p>Get a celery task message consumer.</p>
  261. <table class="docutils field-list" frame="void" rules="none">
  262. <col class="field-name" />
  263. <col class="field-body" />
  264. <tbody valign="top">
  265. <tr class="field"><th class="field-name">Return type:</th><td class="field-body"><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>.</td>
  266. </tr>
  267. </tbody>
  268. </table>
  269. <p>Please be sure to close the AMQP connection when you&#8217;re done
  270. with this object. i.e.:</p>
  271. <div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">consumer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_consumer</span><span class="p">()</span>
  272. <span class="gp">&gt;&gt;&gt; </span><span class="c"># do something with consumer</span>
  273. <span class="gp">&gt;&gt;&gt; </span><span class="n">consumer</span><span class="o">.</span><span class="n">connection</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
  274. </pre></div>
  275. </div>
  276. </dd></dl>
  277. <dl class="method">
  278. <dt id="celery.task.Task.get_logger">
  279. <tt class="descname">get_logger</tt><big>(</big><em>**kwargs</em><big>)</big><a class="headerlink" href="#celery.task.Task.get_logger" title="Permalink to this definition">¶</a></dt>
  280. <dd><p>Get process-aware logger object.</p>
  281. <p>See <a title="celery.log.setup_logger" class="reference external" href="celery.log.html#celery.log.setup_logger"><tt class="xref docutils literal"><span class="pre">celery.log.setup_logger()</span></tt></a>.</p>
  282. </dd></dl>
  283. <dl class="method">
  284. <dt id="celery.task.Task.get_publisher">
  285. <tt class="descname">get_publisher</tt><big>(</big><big>)</big><a class="headerlink" href="#celery.task.Task.get_publisher" title="Permalink to this definition">¶</a></dt>
  286. <dd><p>Get a celery task message publisher.</p>
  287. <table class="docutils field-list" frame="void" rules="none">
  288. <col class="field-name" />
  289. <col class="field-body" />
  290. <tbody valign="top">
  291. <tr class="field"><th class="field-name">Return type:</th><td class="field-body"><a title="celery.messaging.TaskPublisher" class="reference external" href="celery.messaging.html#celery.messaging.TaskPublisher"><tt class="xref docutils literal"><span class="pre">celery.messaging.TaskPublisher</span></tt></a>.</td>
  292. </tr>
  293. </tbody>
  294. </table>
  295. <p>Please be sure to close the AMQP connection when you&#8217;re done
  296. with this object, i.e.:</p>
  297. <div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">publisher</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_publisher</span><span class="p">()</span>
  298. <span class="gp">&gt;&gt;&gt; </span><span class="c"># do something with publisher</span>
  299. <span class="gp">&gt;&gt;&gt; </span><span class="n">publisher</span><span class="o">.</span><span class="n">connection</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
  300. </pre></div>
  301. </div>
  302. </dd></dl>
  303. <dl class="method">
  304. <dt id="celery.task.Task.run">
  305. <tt class="descname">run</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#celery.task.Task.run" title="Permalink to this definition">¶</a></dt>
  306. <dd><p><em>REQUIRED</em> The actual task.</p>
  307. <p>All subclasses of <a title="celery.task.Task" class="reference internal" href="#celery.task.Task"><tt class="xref docutils literal"><span class="pre">Task</span></tt></a> must define the run method.</p>
  308. <table class="docutils field-list" frame="void" rules="none">
  309. <col class="field-name" />
  310. <col class="field-body" />
  311. <tbody valign="top">
  312. <tr class="field"><th class="field-name" colspan="2">Raises NotImplementedError:</th></tr>
  313. <tr><td>&nbsp;</td><td class="field-body">by default, so you have to override
  314. this method in your subclass.</td>
  315. </tr>
  316. </tbody>
  317. </table>
  318. </dd></dl>
  319. </dd></dl>
  320. <dl class="class">
  321. <dt id="celery.task.TaskSet">
  322. <em class="property">
  323. class </em><tt class="descclassname">celery.task.</tt><tt class="descname">TaskSet</tt><big>(</big><em>task</em>, <em>args</em><big>)</big><a class="headerlink" href="#celery.task.TaskSet" title="Permalink to this definition">¶</a></dt>
  324. <dd><p>A task containing several subtasks, making it possible
  325. to track how many, or when all of the tasks has been completed.</p>
  326. <table class="docutils field-list" frame="void" rules="none">
  327. <col class="field-name" />
  328. <col class="field-body" />
  329. <tbody valign="top">
  330. <tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  331. <li><em>task</em> &#8211; The task class or name.
  332. Can either be a fully qualified task name, or a task class.</li>
  333. <li><em>args</em> &#8211; A list of args, kwargs pairs.
  334. e.g. <tt class="docutils literal"><span class="pre">[[args1,</span> <span class="pre">kwargs1],</span> <span class="pre">[args2,</span> <span class="pre">kwargs2],</span> <span class="pre">...,</span> <span class="pre">[argsN,</span> <span class="pre">kwargsN]]</span></tt></li>
  335. </ul>
  336. </td>
  337. </tr>
  338. </tbody>
  339. </table>
  340. <dl class="attribute">
  341. <dt id="celery.task.TaskSet.task_name">
  342. <tt class="descname">task_name</tt><a class="headerlink" href="#celery.task.TaskSet.task_name" title="Permalink to this definition">¶</a></dt>
  343. <dd>The name of the task.</dd></dl>
  344. <dl class="attribute">
  345. <dt id="celery.task.TaskSet.arguments">
  346. <tt class="descname">arguments</tt><a class="headerlink" href="#celery.task.TaskSet.arguments" title="Permalink to this definition">¶</a></dt>
  347. <dd>The arguments, as passed to the task set constructor.</dd></dl>
  348. <dl class="attribute">
  349. <dt id="celery.task.TaskSet.total">
  350. <tt class="descname">total</tt><a class="headerlink" href="#celery.task.TaskSet.total" title="Permalink to this definition">¶</a></dt>
  351. <dd>Total number of tasks in this task set.</dd></dl>
  352. <p>Example</p>
  353. <blockquote>
  354. <div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">djangofeeds.tasks</span> <span class="kn">import</span> <span class="n">RefreshFeedTask</span>
  355. <span class="gp">&gt;&gt;&gt; </span><span class="n">taskset</span> <span class="o">=</span> <span class="n">TaskSet</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>
  356. <span class="gp">... </span> <span class="p">[],</span> <span class="p">{</span><span class="s">&quot;feed_url&quot;</span><span class="p">:</span> <span class="s">&quot;http://cnn.com/rss&quot;</span><span class="p">},</span>
  357. <span class="gp">... </span> <span class="p">[],</span> <span class="p">{</span><span class="s">&quot;feed_url&quot;</span><span class="p">:</span> <span class="s">&quot;http://bbc.com/rss&quot;</span><span class="p">},</span>
  358. <span class="gp">... </span> <span class="p">[],</span> <span class="p">{</span><span class="s">&quot;feed_url&quot;</span><span class="p">:</span> <span class="s">&quot;http://xkcd.com/rss&quot;</span><span class="p">}])</span>
  359. </pre></div>
  360. </div>
  361. <div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">taskset_result</span> <span class="o">=</span> <span class="n">taskset</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
  362. <span class="gp">&gt;&gt;&gt; </span><span class="n">list_of_return_values</span> <span class="o">=</span> <span class="n">taskset</span><span class="o">.</span><span class="n">join</span><span class="p">()</span>
  363. </pre></div>
  364. </div>
  365. </blockquote>
  366. <dl class="method">
  367. <dt id="celery.task.TaskSet.iterate">
  368. <tt class="descname">iterate</tt><big>(</big><big>)</big><a class="headerlink" href="#celery.task.TaskSet.iterate" title="Permalink to this definition">¶</a></dt>
  369. <dd><p>Iterate over the results returned after calling <a title="celery.task.TaskSet.run" class="reference internal" href="#celery.task.TaskSet.run"><tt class="xref docutils literal"><span class="pre">run()</span></tt></a>.</p>
  370. <p>If any of the tasks raises an exception, the exception will
  371. be re-raised.</p>
  372. </dd></dl>
  373. <dl class="method">
  374. <dt id="celery.task.TaskSet.join">
  375. <tt class="descname">join</tt><big>(</big><em>timeout=None</em><big>)</big><a class="headerlink" href="#celery.task.TaskSet.join" title="Permalink to this definition">¶</a></dt>
  376. <dd><p>Gather the results for all of the tasks in the taskset,
  377. and return a list with them ordered by the order of which they
  378. were called.</p>
  379. <table class="docutils field-list" frame="void" rules="none">
  380. <col class="field-name" />
  381. <col class="field-body" />
  382. <tbody valign="top">
  383. <tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>timeout</em> &#8211; The time in seconds, how long
  384. it will wait for results, before the operation times out.</td>
  385. </tr>
  386. <tr class="field"><th class="field-name" colspan="2">Raises <a title="celery.timer.TimeoutError" class="reference external" href="celery.timer.html#celery.timer.TimeoutError">celery.timer.TimeoutError</a>:</th></tr>
  387. <tr><td>&nbsp;</td><td class="field-body">if <tt class="docutils literal"><span class="pre">timeout</span></tt> is not <tt class="xref docutils literal"><span class="pre">None</span></tt>
  388. and the operation takes longer than <tt class="docutils literal"><span class="pre">timeout</span></tt> seconds.</td>
  389. </tr>
  390. </tbody>
  391. </table>
  392. <p>If any of the tasks raises an exception, the exception
  393. will be reraised by <a title="celery.task.TaskSet.join" class="reference internal" href="#celery.task.TaskSet.join"><tt class="xref docutils literal"><span class="pre">join()</span></tt></a>.</p>
  394. <table class="docutils field-list" frame="void" rules="none">
  395. <col class="field-name" />
  396. <col class="field-body" />
  397. <tbody valign="top">
  398. <tr class="field"><th class="field-name">Returns:</th><td class="field-body">list of return values for all tasks in the taskset.</td>
  399. </tr>
  400. </tbody>
  401. </table>
  402. </dd></dl>
  403. <dl class="classmethod">
  404. <dt id="celery.task.TaskSet.map">
  405. <em class="property">
  406. classmethod </em><tt class="descname">map</tt><big>(</big><em>func</em>, <em>args</em>, <em>timeout=None</em><big>)</big><a class="headerlink" href="#celery.task.TaskSet.map" title="Permalink to this definition">¶</a></dt>
  407. <dd>Distribute processing of the arguments and collect the results.</dd></dl>
  408. <dl class="classmethod">
  409. <dt id="celery.task.TaskSet.map_async">
  410. <em class="property">
  411. classmethod </em><tt class="descname">map_async</tt><big>(</big><em>func</em>, <em>args</em>, <em>timeout=None</em><big>)</big><a class="headerlink" href="#celery.task.TaskSet.map_async" title="Permalink to this definition">¶</a></dt>
  412. <dd><p>Distribute processing of the arguments and collect the results
  413. asynchronously.</p>
  414. <table class="docutils field-list" frame="void" rules="none">
  415. <col class="field-name" />
  416. <col class="field-body" />
  417. <tbody valign="top">
  418. <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> instance.</td>
  419. </tr>
  420. </tbody>
  421. </table>
  422. </dd></dl>
  423. <dl class="classmethod">
  424. <dt id="celery.task.TaskSet.remote_execute">
  425. <em class="property">
  426. classmethod </em><tt class="descname">remote_execute</tt><big>(</big><em>func</em>, <em>args</em><big>)</big><a class="headerlink" href="#celery.task.TaskSet.remote_execute" title="Permalink to this definition">¶</a></dt>
  427. <dd>Apply <tt class="docutils literal"><span class="pre">args</span></tt> to function by distributing the args to the
  428. celery server(s).</dd></dl>
  429. <dl class="method">
  430. <dt id="celery.task.TaskSet.run">
  431. <tt class="descname">run</tt><big>(</big><em>connect_timeout=4</em><big>)</big><a class="headerlink" href="#celery.task.TaskSet.run" title="Permalink to this definition">¶</a></dt>
  432. <dd><p>Run all tasks in the taskset.</p>
  433. <table class="docutils field-list" frame="void" rules="none">
  434. <col class="field-name" />
  435. <col class="field-body" />
  436. <tbody valign="top">
  437. <tr class="field"><th class="field-name">Returns:</th><td class="field-body">A <a title="celery.result.TaskSetResult" class="reference external" href="celery.result.html#celery.result.TaskSetResult"><tt class="xref docutils literal"><span class="pre">celery.result.TaskSetResult</span></tt></a> instance.</td>
  438. </tr>
  439. </tbody>
  440. </table>
  441. <p>Example</p>
  442. <div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">ts</span> <span class="o">=</span> <span class="n">TaskSet</span><span class="p">(</span><span class="n">RefreshFeedTask</span><span class="p">,</span> <span class="p">[</span>
  443. <span class="gp">... </span> <span class="p">[</span><span class="s">&quot;http://foo.com/rss&quot;</span><span class="p">,</span> <span class="p">{}],</span>
  444. <span class="gp">... </span> <span class="p">[</span><span class="s">&quot;http://bar.com/rss&quot;</span><span class="p">,</span> <span class="p">{}],</span>
  445. <span class="gp">... </span><span class="p">)</span>
  446. <span class="gp">&gt;&gt;&gt; </span><span class="n">result</span> <span class="o">=</span> <span class="n">ts</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
  447. <span class="gp">&gt;&gt;&gt; </span><span class="n">result</span><span class="o">.</span><span class="n">taskset_id</span>
  448. <span class="go">&quot;d2c9b261-8eff-4bfb-8459-1e1b72063514&quot;</span>
  449. <span class="gp">&gt;&gt;&gt; </span><span class="n">result</span><span class="o">.</span><span class="n">subtask_ids</span>
  450. <span class="go">[&quot;b4996460-d959-49c8-aeb9-39c530dcde25&quot;,</span>
  451. <span class="go">&quot;598d2d18-ab86-45ca-8b4f-0779f5d6a3cb&quot;]</span>
  452. <span class="gp">&gt;&gt;&gt; </span><span class="n">result</span><span class="o">.</span><span class="n">waiting</span><span class="p">()</span>
  453. <span class="go">True</span>
  454. <span class="gp">&gt;&gt;&gt; </span><span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">10</span><span class="p">)</span>
  455. <span class="gp">&gt;&gt;&gt; </span><span class="n">result</span><span class="o">.</span><span class="n">ready</span><span class="p">()</span>
  456. <span class="go">True</span>
  457. <span class="gp">&gt;&gt;&gt; </span><span class="n">result</span><span class="o">.</span><span class="n">successful</span><span class="p">()</span>
  458. <span class="go">True</span>
  459. <span class="gp">&gt;&gt;&gt; </span><span class="n">result</span><span class="o">.</span><span class="n">failed</span><span class="p">()</span>
  460. <span class="go">False</span>
  461. <span class="gp">&gt;&gt;&gt; </span><span class="n">result</span><span class="o">.</span><span class="n">join</span><span class="p">()</span>
  462. <span class="go">[True, True]</span>
  463. </pre></div>
  464. </div>
  465. </dd></dl>
  466. </dd></dl>
  467. <dl class="function">
  468. <dt id="celery.task.apply_async">
  469. <tt class="descclassname">celery.task.</tt><tt class="descname">apply_async</tt><big>(</big><em>task</em>, <em>args=None</em>, <em>kwargs=None</em>, <em>routing_key=None</em>, <em>immediate=None</em>, <em>mandatory=None</em>, <em>connection=None</em>, <em>connect_timeout=4</em>, <em>priority=None</em><big>)</big><a class="headerlink" href="#celery.task.apply_async" title="Permalink to this definition">¶</a></dt>
  470. <dd><p>Run a task asynchronously by the celery daemon(s).</p>
  471. <table class="docutils field-list" frame="void" rules="none">
  472. <col class="field-name" />
  473. <col class="field-body" />
  474. <tbody valign="top">
  475. <tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  476. <li><em>task</em> &#8211; The task to run (a callable object, or a <a title="celery.task.Task" class="reference internal" href="#celery.task.Task"><tt class="xref docutils literal"><span class="pre">Task</span></tt></a>
  477. instance</li>
  478. <li><em>args</em> &#8211; The positional arguments to pass on to the task (a <tt class="docutils literal"><span class="pre">list</span></tt>).</li>
  479. <li><em>kwargs</em> &#8211; The keyword arguments to pass on to the task (a <tt class="docutils literal"><span class="pre">dict</span></tt>)</li>
  480. <li><em>routing_key</em> &#8211; The routing key used to route the task to a worker
  481. server.</li>
  482. <li><em>immediate</em> &#8211; Request immediate delivery. Will raise an exception
  483. if the task cannot be routed to a worker immediately.</li>
  484. <li><em>mandatory</em> &#8211; Mandatory routing. Raises an exception if there&#8217;s
  485. no running workers able to take on this task.</li>
  486. <li><em>connection</em> &#8211; Re-use existing AMQP connection.
  487. The <tt class="docutils literal"><span class="pre">connect_timeout</span></tt> argument is not respected if this is set.</li>
  488. <li><em>connect_timeout</em> &#8211; The timeout in seconds, before we give up
  489. on establishing a connection to the AMQP server.</li>
  490. <li><em>priority</em> &#8211; The task priority, a number between <tt class="docutils literal"><span class="pre">0</span></tt> and <tt class="docutils literal"><span class="pre">9</span></tt>.</li>
  491. </ul>
  492. </td>
  493. </tr>
  494. </tbody>
  495. </table>
  496. </dd></dl>
  497. <dl class="function">
  498. <dt id="celery.task.delay_task">
  499. <tt class="descclassname">celery.task.</tt><tt class="descname">delay_task</tt><big>(</big><em>task_name</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#celery.task.delay_task" title="Permalink to this definition">¶</a></dt>
  500. <dd><p>Delay a task for execution by the <tt class="docutils literal"><span class="pre">celery</span></tt> daemon.</p>
  501. <table class="docutils field-list" frame="void" rules="none">
  502. <col class="field-name" />
  503. <col class="field-body" />
  504. <tbody valign="top">
  505. <tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  506. <li><em>task_name</em> &#8211; the name of a task registered in the task registry.</li>
  507. <li><em>*args</em> &#8211; positional arguments to pass on to the task.</li>
  508. <li><em>**kwargs</em> &#8211; keyword arguments to pass on to the task.</li>
  509. </ul>
  510. </td>
  511. </tr>
  512. <tr class="field"><th class="field-name" colspan="2">Raises <a title="celery.registry.NotRegistered" class="reference external" href="celery.registry.html#celery.registry.NotRegistered">celery.registry.NotRegistered</a>:</th></tr>
  513. <tr><td>&nbsp;</td><td class="field-body"><p class="first">exception if no such task
  514. has been registered in the task registry.</p>
  515. </td>
  516. </tr>
  517. <tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last"><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>.</p>
  518. </td>
  519. </tr>
  520. </tbody>
  521. </table>
  522. <p>Example</p>
  523. <div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">r</span> <span class="o">=</span> <span class="n">delay_task</span><span class="p">(</span><span class="s">&quot;update_record&quot;</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;George Constanza&quot;</span><span class="p">,</span> <span class="n">age</span><span class="o">=</span><span class="mf">32</span><span class="p">)</span>
  524. <span class="gp">&gt;&gt;&gt; </span><span class="n">r</span><span class="o">.</span><span class="n">ready</span><span class="p">()</span>
  525. <span class="go">True</span>
  526. <span class="gp">&gt;&gt;&gt; </span><span class="n">r</span><span class="o">.</span><span class="n">result</span>
  527. <span class="go">&quot;Record was updated&quot;</span>
  528. </pre></div>
  529. </div>
  530. </dd></dl>
  531. <dl class="function">
  532. <dt id="celery.task.discard_all">
  533. <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>
  534. <dd><p>Discard all waiting tasks.</p>
  535. <p>This will ignore all tasks waiting for execution, and they will
  536. be deleted from the messaging server.</p>
  537. <table class="docutils field-list" frame="void" rules="none">
  538. <col class="field-name" />
  539. <col class="field-body" />
  540. <tbody valign="top">
  541. <tr class="field"><th class="field-name">Returns:</th><td class="field-body">the number of tasks discarded.</td>
  542. </tr>
  543. <tr class="field"><th class="field-name">Return type:</th><td class="field-body">int</td>
  544. </tr>
  545. </tbody>
  546. </table>
  547. </dd></dl>
  548. <dl class="function">
  549. <dt id="celery.task.dmap">
  550. <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>
  551. <dd><p>Distribute processing of the arguments and collect the results.</p>
  552. <p>Example</p>
  553. <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="nb">map</span>
  554. <span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">operator</span>
  555. <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>
  556. <span class="go">[4, 8, 16]</span>
  557. </pre></div>
  558. </div>
  559. </dd></dl>
  560. <dl class="function">
  561. <dt id="celery.task.dmap_async">
  562. <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>
  563. <dd><p>Distribute processing of the arguments and collect the results
  564. asynchronously.</p>
  565. <table class="docutils field-list" frame="void" rules="none">
  566. <col class="field-name" />
  567. <col class="field-body" />
  568. <tbody valign="top">
  569. <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>
  570. </tr>
  571. </tbody>
  572. </table>
  573. <p>Example</p>
  574. <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>
  575. <span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">operator</span>
  576. <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>
  577. <span class="gp">&gt;&gt;&gt; </span><span class="n">presult</span>
  578. <span class="go">&lt;AsyncResult: 373550e8-b9a0-4666-bc61-ace01fa4f91d&gt;</span>
  579. <span class="gp">&gt;&gt;&gt; </span><span class="n">presult</span><span class="o">.</span><span class="n">status</span>
  580. <span class="go">&#39;DONE&#39;</span>
  581. <span class="gp">&gt;&gt;&gt; </span><span class="n">presult</span><span class="o">.</span><span class="n">result</span>
  582. <span class="go">[4, 8, 16]</span>
  583. </pre></div>
  584. </div>
  585. </dd></dl>
  586. <dl class="function">
  587. <dt id="celery.task.execute_remote">
  588. <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>
  589. <dd><p>Execute arbitrary function/object remotely.</p>
  590. <table class="docutils field-list" frame="void" rules="none">
  591. <col class="field-name" />
  592. <col class="field-body" />
  593. <tbody valign="top">
  594. <tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  595. <li><em>func</em> &#8211; A callable function or object.</li>
  596. <li><em>*args</em> &#8211; Positional arguments to apply to the function.</li>
  597. <li><em>**kwargs</em> &#8211; Keyword arguments to apply to the function.</li>
  598. </ul>
  599. </td>
  600. </tr>
  601. </tbody>
  602. </table>
  603. <p>The object must be picklable, so you can&#8217;t use lambdas or functions
  604. defined in the REPL (the objects must have an associated module).</p>
  605. <table class="docutils field-list" frame="void" rules="none">
  606. <col class="field-name" />
  607. <col class="field-body" />
  608. <tbody valign="top">
  609. <tr class="field"><th class="field-name">Returns:</th><td class="field-body">class:<cite>celery.result.AsyncResult</cite>.</td>
  610. </tr>
  611. </tbody>
  612. </table>
  613. </dd></dl>
  614. <dl class="function">
  615. <dt id="celery.task.is_done">
  616. <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>
  617. <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>
  618. <table class="docutils field-list" frame="void" rules="none">
  619. <col class="field-name" />
  620. <col class="field-body" />
  621. <tbody valign="top">
  622. <tr class="field"><th class="field-name">Return type:</th><td class="field-body">bool</td>
  623. </tr>
  624. </tbody>
  625. </table>
  626. </dd></dl>
  627. <dl class="function">
  628. <dt id="celery.task.ping">
  629. <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>
  630. <dd><p>Test if the server is alive.</p>
  631. <p>Example:</p>
  632. <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>
  633. <span class="gp">&gt;&gt;&gt; </span><span class="n">ping</span><span class="p">()</span>
  634. <span class="go">&#39;pong&#39;</span>
  635. </pre></div>
  636. </div>
  637. </dd></dl>
  638. </div>
  639. </div>
  640. </div>
  641. </div>
  642. </div>
  643. <div class="sidebar">
  644. <h3>Contents</h3>
  645. <ul class="current">
  646. <li class="toctree-l1"><a class="reference external" href="../introduction.html">celery - Distributed Task Queue for Django.</a></li>
  647. <li class="toctree-l1"><a class="reference external" href="../faq.html">Frequently Asked Questions</a></li>
  648. <li class="toctree-l1 current"><a class="reference external" href="index.html">Module API Reference</a><ul class="current">
  649. <li class="toctree-l2 current"><a class="current reference external" href="">Tasks - celery.task</a></li>
  650. <li class="toctree-l2"><a class="reference external" href="celery.result.html">Task Result - celery.result</a></li>
  651. <li class="toctree-l2"><a class="reference external" href="celery.registry.html">Task Registry - celery.registry</a></li>
  652. <li class="toctree-l2"><a class="reference external" href="celery.discovery.html">Task Discovery - celery.discovery</a></li>
  653. <li class="toctree-l2"><a class="reference external" href="celery.worker.html">Multiprocessing Worker - celery.worker</a></li>
  654. <li class="toctree-l2"><a class="reference external" href="celery.pool.html">Task Pool - celery.pool</a></li>
  655. <li class="toctree-l2"><a class="reference external" href="celery.backends.html">Backends - celery.backends</a></li>
  656. <li class="toctree-l2"><a class="reference external" href="celery.backends.base.html">Backend: Base - celery.backends.base</a></li>
  657. <li class="toctree-l2"><a class="reference external" href="celery.backends.database.html">Backend: Database - celery.backends.database</a></li>
  658. <li class="toctree-l2"><a class="reference external" href="celery.backends.cache.html">Backend: Cache - celery.backends.cache</a></li>
  659. <li class="toctree-l2"><a class="reference external" href="celery.backends.tyrant.html">Backend: Tokyo Tyrant - celery.backends.tyrant</a></li>
  660. <li class="toctree-l2"><a class="reference external" href="celery.conf.html">Configuration - celery.conf</a></li>
  661. <li class="toctree-l2"><a class="reference external" href="celery.datastructures.html">Datastructures - celery.datastructures</a></li>
  662. <li class="toctree-l2"><a class="reference external" href="celery.log.html">Logging - celery.log</a></li>
  663. <li class="toctree-l2"><a class="reference external" href="celery.managers.html">Django Model Managers - celery.managers</a></li>
  664. <li class="toctree-l2"><a class="reference external" href="celery.models.html">Django Models - celery.models</a></li>
  665. <li class="toctree-l2"><a class="reference external" href="celery.messaging.html">Messaging - celery.messaging</a></li>
  666. <li class="toctree-l2"><a class="reference external" href="celery.timer.html">Timers - celery.timer</a></li>
  667. <li class="toctree-l2"><a class="reference external" href="celery.bin.celeryd.html">Celery Worker Daemon - celery.bin.celeryd</a></li>
  668. </ul>
  669. </li>
  670. <li class="toctree-l1"><a class="reference external" href="../changelog.html">Change history</a></li>
  671. </ul>
  672. <h3 style="margin-top: 1.5em;">Search</h3>
  673. <form class="search" action="../search.html" method="get">
  674. <input type="text" name="q" size="18" />
  675. <input type="submit" value="Go" />
  676. <input type="hidden" name="check_keywords" value="yes" />
  677. <input type="hidden" name="area" value="default" />
  678. </form>
  679. <p class="searchtip" style="font-size: 90%">
  680. Enter search terms or a module, class or function name.
  681. </p>
  682. </div>
  683. <div class="clearer"></div>
  684. </div>
  685. </div>
  686. <div class="footer-wrapper">
  687. <div class="footer">
  688. <div class="left">
  689. <a href="../genindex.html" title="General Index"
  690. >index</a> |
  691. <a href="../modindex.html" title="Global Module Index"
  692. >modules</a> |
  693. <a href="celery.result.html" title="Task Result - celery.result"
  694. >next</a> |
  695. <a href="index.html" title="Module API Reference"
  696. >previous</a>
  697. <br/>
  698. <a href="../sources/reference/celery.task.txt"
  699. rel="nofollow">Show Source</a>
  700. </div>
  701. <div class="right">
  702. &copy; Copyright 2009, Ask Solem.<br/>
  703. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.1.
  704. </div>
  705. <div class="clearer"></div>
  706. </div>
  707. </div>
  708. </body>
  709. </html>