celery.task.html 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  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.11 (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.11 (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.11 (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.11 (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. <dl class="attribute">
  175. <dt id="celery.task.Task.routing_key">
  176. <tt class="descname">routing_key</tt><a class="headerlink" href="#celery.task.Task.routing_key" title="Permalink to this definition">¶</a></dt>
  177. <dd>Override the global default <a href="#id1"><span class="problematic" id="id2">``</span></a>routing_key``[#f1]_ for this task.</dd></dl>
  178. <table class="docutils footnote" frame="void" id="f1" rules="none">
  179. <colgroup><col class="label" /><col /></colgroup>
  180. <tbody valign="top">
  181. <tr><td class="label">[1]</td><td><tt class="docutils literal"><span class="pre">settings.CELERY_AMQP_PUBLISHER_ROUTING_KEY</span></tt></td></tr>
  182. </tbody>
  183. </table>
  184. <dl class="attribute">
  185. <dt id="celery.task.Task.mandatory">
  186. <tt class="descname">mandatory</tt><a class="headerlink" href="#celery.task.Task.mandatory" title="Permalink to this definition">¶</a></dt>
  187. <dd>If set, the message has mandatory routing. By default the message
  188. is silently dropped by the broker if it can&#8217;t be routed to a queue.
  189. However - If the message is mandatory, an exception will be raised
  190. instead.</dd></dl>
  191. <dl class="attribute">
  192. <dt>
  193. <tt class="descname">immediate:</tt></dt>
  194. <dd>Request immediate delivery. If the message cannot be routed to a
  195. task worker immediately, an exception will be raised. This is
  196. instead of the default behaviour, where the broker will accept and
  197. queue the message, but with no guarantee that the message will ever
  198. be consumed.</dd></dl>
  199. <dl class="attribute">
  200. <dt>
  201. <tt class="descname">priority:</tt></dt>
  202. <dd>The message priority. A number from <tt class="docutils literal"><span class="pre">0</span></tt> to <tt class="docutils literal"><span class="pre">9</span></tt>.</dd></dl>
  203. <dl class="attribute">
  204. <dt id="celery.task.Task.disable_error_emails">
  205. <tt class="descname">disable_error_emails</tt><a class="headerlink" href="#celery.task.Task.disable_error_emails" title="Permalink to this definition">¶</a></dt>
  206. <dd>Disable all error e-mails for this task (only applicable if
  207. <tt class="docutils literal"><span class="pre">settings.SEND_CELERY_ERROR_EMAILS</span></tt> is on).</dd></dl>
  208. <table class="docutils field-list" frame="void" rules="none">
  209. <col class="field-name" />
  210. <col class="field-body" />
  211. <tbody valign="top">
  212. <tr class="field"><th class="field-name" colspan="2">Raises NotImplementedError:</th></tr>
  213. <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>
  214. </tr>
  215. </tbody>
  216. </table>
  217. <p>The resulting class is callable, which if called will apply the
  218. <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>
  219. <p>Examples</p>
  220. <p>This is a simple task just logging a message,</p>
  221. <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>
  222. <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>
  223. <span class="gp">... </span> <span class="n">name</span> <span class="o">=</span> <span class="s">&quot;mytask&quot;</span>
  224. <span class="gp">...</span>
  225. <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>
  226. <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>
  227. <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>
  228. <span class="gp">... </span> <span class="n">some_arg</span><span class="p">))</span>
  229. <span class="gp">... </span> <span class="k">return</span> <span class="mf">42</span>
  230. <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>
  231. </pre></div>
  232. </div>
  233. <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>
  234. <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>
  235. <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>
  236. <span class="go">&#39;DONE&#39;</span>
  237. <span class="gp">&gt;&gt;&gt; </span><span class="n">result</span><span class="o">.</span><span class="n">result</span>
  238. <span class="go">42</span>
  239. </pre></div>
  240. </div>
  241. <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
  242. the task.</p>
  243. <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>
  244. <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>
  245. </pre></div>
  246. </div>
  247. <dl class="classmethod">
  248. <dt id="celery.task.Task.apply_async">
  249. <em class="property">
  250. 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>
  251. <dd><p>Delay this task for execution by the <tt class="docutils literal"><span class="pre">celery</span></tt> daemon(s).</p>
  252. <table class="docutils field-list" frame="void" rules="none">
  253. <col class="field-name" />
  254. <col class="field-body" />
  255. <tbody valign="top">
  256. <tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  257. <li><em>args</em> &#8211; positional arguments passed on to the task.</li>
  258. <li><em>kwargs</em> &#8211; keyword arguments passed on to the task.</li>
  259. </ul>
  260. </td>
  261. </tr>
  262. <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>
  263. </td>
  264. </tr>
  265. </tbody>
  266. </table>
  267. <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>
  268. </dd></dl>
  269. <dl class="classmethod">
  270. <dt id="celery.task.Task.delay">
  271. <em class="property">
  272. 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>
  273. <dd><p>Delay this task for execution by the <tt class="docutils literal"><span class="pre">celery</span></tt> daemon(s).</p>
  274. <table class="docutils field-list" frame="void" rules="none">
  275. <col class="field-name" />
  276. <col class="field-body" />
  277. <tbody valign="top">
  278. <tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  279. <li><em>*args</em> &#8211; positional arguments passed on to the task.</li>
  280. <li><em>**kwargs</em> &#8211; keyword arguments passed on to the task.</li>
  281. </ul>
  282. </td>
  283. </tr>
  284. <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>
  285. </td>
  286. </tr>
  287. </tbody>
  288. </table>
  289. <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>
  290. </dd></dl>
  291. <dl class="method">
  292. <dt id="celery.task.Task.get_consumer">
  293. <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>
  294. <dd><p>Get a celery task message consumer.</p>
  295. <table class="docutils field-list" frame="void" rules="none">
  296. <col class="field-name" />
  297. <col class="field-body" />
  298. <tbody valign="top">
  299. <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>
  300. </tr>
  301. </tbody>
  302. </table>
  303. <p>Please be sure to close the AMQP connection when you&#8217;re done
  304. with this object. i.e.:</p>
  305. <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>
  306. <span class="gp">&gt;&gt;&gt; </span><span class="c"># do something with consumer</span>
  307. <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>
  308. </pre></div>
  309. </div>
  310. </dd></dl>
  311. <dl class="method">
  312. <dt id="celery.task.Task.get_logger">
  313. <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>
  314. <dd><p>Get process-aware logger object.</p>
  315. <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>
  316. </dd></dl>
  317. <dl class="method">
  318. <dt id="celery.task.Task.get_publisher">
  319. <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>
  320. <dd><p>Get a celery task message publisher.</p>
  321. <table class="docutils field-list" frame="void" rules="none">
  322. <col class="field-name" />
  323. <col class="field-body" />
  324. <tbody valign="top">
  325. <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>
  326. </tr>
  327. </tbody>
  328. </table>
  329. <p>Please be sure to close the AMQP connection when you&#8217;re done
  330. with this object, i.e.:</p>
  331. <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>
  332. <span class="gp">&gt;&gt;&gt; </span><span class="c"># do something with publisher</span>
  333. <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>
  334. </pre></div>
  335. </div>
  336. </dd></dl>
  337. <dl class="method">
  338. <dt id="celery.task.Task.run">
  339. <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>
  340. <dd><p><em>REQUIRED</em> The actual task.</p>
  341. <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>
  342. <table class="docutils field-list" frame="void" rules="none">
  343. <col class="field-name" />
  344. <col class="field-body" />
  345. <tbody valign="top">
  346. <tr class="field"><th class="field-name" colspan="2">Raises NotImplementedError:</th></tr>
  347. <tr><td>&nbsp;</td><td class="field-body">by default, so you have to override
  348. this method in your subclass.</td>
  349. </tr>
  350. </tbody>
  351. </table>
  352. </dd></dl>
  353. </dd></dl>
  354. <dl class="class">
  355. <dt id="celery.task.TaskSet">
  356. <em class="property">
  357. 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>
  358. <dd><p>A task containing several subtasks, making it possible
  359. to track how many, or when all of the tasks has been completed.</p>
  360. <table class="docutils field-list" frame="void" rules="none">
  361. <col class="field-name" />
  362. <col class="field-body" />
  363. <tbody valign="top">
  364. <tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  365. <li><em>task</em> &#8211; The task class or name.
  366. Can either be a fully qualified task name, or a task class.</li>
  367. <li><em>args</em> &#8211; A list of args, kwargs pairs.
  368. 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>
  369. </ul>
  370. </td>
  371. </tr>
  372. </tbody>
  373. </table>
  374. <dl class="attribute">
  375. <dt id="celery.task.TaskSet.task_name">
  376. <tt class="descname">task_name</tt><a class="headerlink" href="#celery.task.TaskSet.task_name" title="Permalink to this definition">¶</a></dt>
  377. <dd>The name of the task.</dd></dl>
  378. <dl class="attribute">
  379. <dt id="celery.task.TaskSet.arguments">
  380. <tt class="descname">arguments</tt><a class="headerlink" href="#celery.task.TaskSet.arguments" title="Permalink to this definition">¶</a></dt>
  381. <dd>The arguments, as passed to the task set constructor.</dd></dl>
  382. <dl class="attribute">
  383. <dt id="celery.task.TaskSet.total">
  384. <tt class="descname">total</tt><a class="headerlink" href="#celery.task.TaskSet.total" title="Permalink to this definition">¶</a></dt>
  385. <dd>Total number of tasks in this task set.</dd></dl>
  386. <p>Example</p>
  387. <blockquote>
  388. <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>
  389. <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>
  390. <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>
  391. <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>
  392. <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>
  393. </pre></div>
  394. </div>
  395. <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>
  396. <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>
  397. </pre></div>
  398. </div>
  399. </blockquote>
  400. <dl class="method">
  401. <dt id="celery.task.TaskSet.iterate">
  402. <tt class="descname">iterate</tt><big>(</big><big>)</big><a class="headerlink" href="#celery.task.TaskSet.iterate" title="Permalink to this definition">¶</a></dt>
  403. <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>
  404. <p>If any of the tasks raises an exception, the exception will
  405. be re-raised.</p>
  406. </dd></dl>
  407. <dl class="method">
  408. <dt id="celery.task.TaskSet.join">
  409. <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>
  410. <dd><p>Gather the results for all of the tasks in the taskset,
  411. and return a list with them ordered by the order of which they
  412. were called.</p>
  413. <table class="docutils field-list" frame="void" rules="none">
  414. <col class="field-name" />
  415. <col class="field-body" />
  416. <tbody valign="top">
  417. <tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>timeout</em> &#8211; The time in seconds, how long
  418. it will wait for results, before the operation times out.</td>
  419. </tr>
  420. <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>
  421. <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>
  422. and the operation takes longer than <tt class="docutils literal"><span class="pre">timeout</span></tt> seconds.</td>
  423. </tr>
  424. </tbody>
  425. </table>
  426. <p>If any of the tasks raises an exception, the exception
  427. 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>
  428. <table class="docutils field-list" frame="void" rules="none">
  429. <col class="field-name" />
  430. <col class="field-body" />
  431. <tbody valign="top">
  432. <tr class="field"><th class="field-name">Returns:</th><td class="field-body">list of return values for all tasks in the taskset.</td>
  433. </tr>
  434. </tbody>
  435. </table>
  436. </dd></dl>
  437. <dl class="classmethod">
  438. <dt id="celery.task.TaskSet.map">
  439. <em class="property">
  440. 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>
  441. <dd>Distribute processing of the arguments and collect the results.</dd></dl>
  442. <dl class="classmethod">
  443. <dt id="celery.task.TaskSet.map_async">
  444. <em class="property">
  445. 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>
  446. <dd><p>Distribute processing of the arguments and collect the results
  447. asynchronously.</p>
  448. <table class="docutils field-list" frame="void" rules="none">
  449. <col class="field-name" />
  450. <col class="field-body" />
  451. <tbody valign="top">
  452. <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>
  453. </tr>
  454. </tbody>
  455. </table>
  456. </dd></dl>
  457. <dl class="classmethod">
  458. <dt id="celery.task.TaskSet.remote_execute">
  459. <em class="property">
  460. 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>
  461. <dd>Apply <tt class="docutils literal"><span class="pre">args</span></tt> to function by distributing the args to the
  462. celery server(s).</dd></dl>
  463. <dl class="method">
  464. <dt id="celery.task.TaskSet.run">
  465. <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>
  466. <dd><p>Run all tasks in the taskset.</p>
  467. <table class="docutils field-list" frame="void" rules="none">
  468. <col class="field-name" />
  469. <col class="field-body" />
  470. <tbody valign="top">
  471. <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>
  472. </tr>
  473. </tbody>
  474. </table>
  475. <p>Example</p>
  476. <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>
  477. <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>
  478. <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>
  479. <span class="gp">... </span><span class="p">)</span>
  480. <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>
  481. <span class="gp">&gt;&gt;&gt; </span><span class="n">result</span><span class="o">.</span><span class="n">taskset_id</span>
  482. <span class="go">&quot;d2c9b261-8eff-4bfb-8459-1e1b72063514&quot;</span>
  483. <span class="gp">&gt;&gt;&gt; </span><span class="n">result</span><span class="o">.</span><span class="n">subtask_ids</span>
  484. <span class="go">[&quot;b4996460-d959-49c8-aeb9-39c530dcde25&quot;,</span>
  485. <span class="go">&quot;598d2d18-ab86-45ca-8b4f-0779f5d6a3cb&quot;]</span>
  486. <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>
  487. <span class="go">True</span>
  488. <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>
  489. <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>
  490. <span class="go">True</span>
  491. <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>
  492. <span class="go">True</span>
  493. <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>
  494. <span class="go">False</span>
  495. <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>
  496. <span class="go">[True, True]</span>
  497. </pre></div>
  498. </div>
  499. </dd></dl>
  500. </dd></dl>
  501. <dl class="function">
  502. <dt id="celery.task.apply_async">
  503. <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>, <em>**opts</em><big>)</big><a class="headerlink" href="#celery.task.apply_async" title="Permalink to this definition">¶</a></dt>
  504. <dd><p>Run a task asynchronously by the celery daemon(s).</p>
  505. <table class="docutils field-list" frame="void" rules="none">
  506. <col class="field-name" />
  507. <col class="field-body" />
  508. <tbody valign="top">
  509. <tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  510. <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>
  511. instance</li>
  512. <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>
  513. <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>
  514. <li><em>routing_key</em> &#8211; The routing key used to route the task to a worker
  515. server.</li>
  516. <li><em>immediate</em> &#8211; Request immediate delivery. Will raise an exception
  517. if the task cannot be routed to a worker immediately.</li>
  518. <li><em>mandatory</em> &#8211; Mandatory routing. Raises an exception if there&#8217;s
  519. no running workers able to take on this task.</li>
  520. <li><em>connection</em> &#8211; Re-use existing AMQP connection.
  521. The <tt class="docutils literal"><span class="pre">connect_timeout</span></tt> argument is not respected if this is set.</li>
  522. <li><em>connect_timeout</em> &#8211; The timeout in seconds, before we give up
  523. on establishing a connection to the AMQP server.</li>
  524. <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>
  525. </ul>
  526. </td>
  527. </tr>
  528. </tbody>
  529. </table>
  530. </dd></dl>
  531. <dl class="function">
  532. <dt id="celery.task.delay_task">
  533. <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>
  534. <dd><p>Delay a task for execution by the <tt class="docutils literal"><span class="pre">celery</span></tt> daemon.</p>
  535. <table class="docutils field-list" frame="void" rules="none">
  536. <col class="field-name" />
  537. <col class="field-body" />
  538. <tbody valign="top">
  539. <tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  540. <li><em>task_name</em> &#8211; the name of a task registered in the task registry.</li>
  541. <li><em>*args</em> &#8211; positional arguments to pass on to the task.</li>
  542. <li><em>**kwargs</em> &#8211; keyword arguments to pass on to the task.</li>
  543. </ul>
  544. </td>
  545. </tr>
  546. <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>
  547. <tr><td>&nbsp;</td><td class="field-body"><p class="first">exception if no such task
  548. has been registered in the task registry.</p>
  549. </td>
  550. </tr>
  551. <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>
  552. </td>
  553. </tr>
  554. </tbody>
  555. </table>
  556. <p>Example</p>
  557. <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>
  558. <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>
  559. <span class="go">True</span>
  560. <span class="gp">&gt;&gt;&gt; </span><span class="n">r</span><span class="o">.</span><span class="n">result</span>
  561. <span class="go">&quot;Record was updated&quot;</span>
  562. </pre></div>
  563. </div>
  564. </dd></dl>
  565. <dl class="function">
  566. <dt id="celery.task.discard_all">
  567. <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>
  568. <dd><p>Discard all waiting tasks.</p>
  569. <p>This will ignore all tasks waiting for execution, and they will
  570. be deleted from the messaging server.</p>
  571. <table class="docutils field-list" frame="void" rules="none">
  572. <col class="field-name" />
  573. <col class="field-body" />
  574. <tbody valign="top">
  575. <tr class="field"><th class="field-name">Returns:</th><td class="field-body">the number of tasks discarded.</td>
  576. </tr>
  577. <tr class="field"><th class="field-name">Return type:</th><td class="field-body">int</td>
  578. </tr>
  579. </tbody>
  580. </table>
  581. </dd></dl>
  582. <dl class="function">
  583. <dt id="celery.task.dmap">
  584. <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>
  585. <dd><p>Distribute processing of the arguments and collect the results.</p>
  586. <p>Example</p>
  587. <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>
  588. <span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">operator</span>
  589. <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>
  590. <span class="go">[4, 8, 16]</span>
  591. </pre></div>
  592. </div>
  593. </dd></dl>
  594. <dl class="function">
  595. <dt id="celery.task.dmap_async">
  596. <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>
  597. <dd><p>Distribute processing of the arguments and collect the results
  598. asynchronously.</p>
  599. <table class="docutils field-list" frame="void" rules="none">
  600. <col class="field-name" />
  601. <col class="field-body" />
  602. <tbody valign="top">
  603. <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>
  604. </tr>
  605. </tbody>
  606. </table>
  607. <p>Example</p>
  608. <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>
  609. <span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">operator</span>
  610. <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>
  611. <span class="gp">&gt;&gt;&gt; </span><span class="n">presult</span>
  612. <span class="go">&lt;AsyncResult: 373550e8-b9a0-4666-bc61-ace01fa4f91d&gt;</span>
  613. <span class="gp">&gt;&gt;&gt; </span><span class="n">presult</span><span class="o">.</span><span class="n">status</span>
  614. <span class="go">&#39;DONE&#39;</span>
  615. <span class="gp">&gt;&gt;&gt; </span><span class="n">presult</span><span class="o">.</span><span class="n">result</span>
  616. <span class="go">[4, 8, 16]</span>
  617. </pre></div>
  618. </div>
  619. </dd></dl>
  620. <dl class="function">
  621. <dt id="celery.task.execute_remote">
  622. <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>
  623. <dd><p>Execute arbitrary function/object remotely.</p>
  624. <table class="docutils field-list" frame="void" rules="none">
  625. <col class="field-name" />
  626. <col class="field-body" />
  627. <tbody valign="top">
  628. <tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  629. <li><em>func</em> &#8211; A callable function or object.</li>
  630. <li><em>*args</em> &#8211; Positional arguments to apply to the function.</li>
  631. <li><em>**kwargs</em> &#8211; Keyword arguments to apply to the function.</li>
  632. </ul>
  633. </td>
  634. </tr>
  635. </tbody>
  636. </table>
  637. <p>The object must be picklable, so you can&#8217;t use lambdas or functions
  638. defined in the REPL (the objects must have an associated module).</p>
  639. <table class="docutils field-list" frame="void" rules="none">
  640. <col class="field-name" />
  641. <col class="field-body" />
  642. <tbody valign="top">
  643. <tr class="field"><th class="field-name">Returns:</th><td class="field-body">class:<cite>celery.result.AsyncResult</cite>.</td>
  644. </tr>
  645. </tbody>
  646. </table>
  647. </dd></dl>
  648. <dl class="function">
  649. <dt id="celery.task.is_done">
  650. <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>
  651. <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>
  652. <table class="docutils field-list" frame="void" rules="none">
  653. <col class="field-name" />
  654. <col class="field-body" />
  655. <tbody valign="top">
  656. <tr class="field"><th class="field-name">Return type:</th><td class="field-body">bool</td>
  657. </tr>
  658. </tbody>
  659. </table>
  660. </dd></dl>
  661. <dl class="function">
  662. <dt id="celery.task.ping">
  663. <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>
  664. <dd><p>Test if the server is alive.</p>
  665. <p>Example:</p>
  666. <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>
  667. <span class="gp">&gt;&gt;&gt; </span><span class="n">ping</span><span class="p">()</span>
  668. <span class="go">&#39;pong&#39;</span>
  669. </pre></div>
  670. </div>
  671. </dd></dl>
  672. </div>
  673. </div>
  674. </div>
  675. </div>
  676. </div>
  677. <div class="sidebar">
  678. <h3>Contents</h3>
  679. <ul class="current">
  680. <li class="toctree-l1"><a class="reference external" href="../introduction.html">celery - Distributed Task Queue for Django.</a></li>
  681. <li class="toctree-l1"><a class="reference external" href="../faq.html">Frequently Asked Questions</a></li>
  682. <li class="toctree-l1 current"><a class="reference external" href="index.html">Module API Reference</a><ul class="current">
  683. <li class="toctree-l2 current"><a class="current reference external" href="">Tasks - celery.task</a></li>
  684. <li class="toctree-l2"><a class="reference external" href="celery.result.html">Task Result - celery.result</a></li>
  685. <li class="toctree-l2"><a class="reference external" href="celery.registry.html">Task Registry - celery.registry</a></li>
  686. <li class="toctree-l2"><a class="reference external" href="celery.discovery.html">Task Discovery - celery.discovery</a></li>
  687. <li class="toctree-l2"><a class="reference external" href="celery.monitoring.html">Statistics and Monitoring - celery.monitoring</a></li>
  688. <li class="toctree-l2"><a class="reference external" href="celery.worker.html">Multiprocessing Worker - celery.worker</a></li>
  689. <li class="toctree-l2"><a class="reference external" href="celery.pool.html">Task Pool - celery.pool</a></li>
  690. <li class="toctree-l2"><a class="reference external" href="celery.backends.html">Backends - celery.backends</a></li>
  691. <li class="toctree-l2"><a class="reference external" href="celery.backends.base.html">Backend: Base - celery.backends.base</a></li>
  692. <li class="toctree-l2"><a class="reference external" href="celery.backends.database.html">Backend: Database - celery.backends.database</a></li>
  693. <li class="toctree-l2"><a class="reference external" href="celery.backends.cache.html">Backend: Cache - celery.backends.cache</a></li>
  694. <li class="toctree-l2"><a class="reference external" href="celery.backends.tyrant.html">Backend: Tokyo Tyrant - celery.backends.tyrant</a></li>
  695. <li class="toctree-l2"><a class="reference external" href="celery.conf.html">Configuration - celery.conf</a></li>
  696. <li class="toctree-l2"><a class="reference external" href="celery.datastructures.html">Datastructures - celery.datastructures</a></li>
  697. <li class="toctree-l2"><a class="reference external" href="celery.log.html">Logging - celery.log</a></li>
  698. <li class="toctree-l2"><a class="reference external" href="celery.managers.html">Django Model Managers - celery.managers</a></li>
  699. <li class="toctree-l2"><a class="reference external" href="celery.models.html">Django Models - celery.models</a></li>
  700. <li class="toctree-l2"><a class="reference external" href="celery.messaging.html">Messaging - celery.messaging</a></li>
  701. <li class="toctree-l2"><a class="reference external" href="celery.timer.html">Timers - celery.timer</a></li>
  702. <li class="toctree-l2"><a class="reference external" href="celery.bin.celeryd.html">Celery Worker Daemon - celery.bin.celeryd</a></li>
  703. </ul>
  704. </li>
  705. <li class="toctree-l1"><a class="reference external" href="../changelog.html">Change history</a></li>
  706. </ul>
  707. <h3 style="margin-top: 1.5em;">Search</h3>
  708. <form class="search" action="../search.html" method="get">
  709. <input type="text" name="q" size="18" />
  710. <input type="submit" value="Go" />
  711. <input type="hidden" name="check_keywords" value="yes" />
  712. <input type="hidden" name="area" value="default" />
  713. </form>
  714. <p class="searchtip" style="font-size: 90%">
  715. Enter search terms or a module, class or function name.
  716. </p>
  717. </div>
  718. <div class="clearer"></div>
  719. </div>
  720. </div>
  721. <div class="footer-wrapper">
  722. <div class="footer">
  723. <div class="left">
  724. <a href="../genindex.html" title="General Index"
  725. >index</a> |
  726. <a href="../modindex.html" title="Global Module Index"
  727. >modules</a> |
  728. <a href="celery.result.html" title="Task Result - celery.result"
  729. >next</a> |
  730. <a href="index.html" title="Module API Reference"
  731. >previous</a>
  732. <br/>
  733. <a href="../sources/reference/celery.task.txt"
  734. rel="nofollow">Show Source</a>
  735. </div>
  736. <div class="right">
  737. &copy; Copyright 2009, Ask Solem.<br/>
  738. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.1.
  739. </div>
  740. <div class="clearer"></div>
  741. </div>
  742. </div>
  743. </body>
  744. </html>