celery.task.html 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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.1.14 documentation</title>
  7. <link rel="stylesheet" href="../static/default.css" type="text/css" />
  8. <link rel="stylesheet" href="../static/pygments.css" type="text/css" />
  9. <script type="text/javascript">
  10. var DOCUMENTATION_OPTIONS = {
  11. URL_ROOT: '../',
  12. VERSION: '0.1.14',
  13. COLLAPSE_MODINDEX: false,
  14. FILE_SUFFIX: '.html',
  15. HAS_SOURCE: true
  16. };
  17. </script>
  18. <script type="text/javascript" src="../static/jquery.js"></script>
  19. <script type="text/javascript" src="../static/doctools.js"></script>
  20. <link rel="top" title="Celery v0.1.14 documentation" href="../index.html" />
  21. <link rel="next" title="Task Result - celery.result" href="celery.result.html" />
  22. <link rel="prev" title="Welcome to Celery’s documentation!" href="../index.html" />
  23. </head>
  24. <body>
  25. <div class="related">
  26. <h3>Navigation</h3>
  27. <ul>
  28. <li class="right" style="margin-right: 10px">
  29. <a href="../genindex.html" title="General Index"
  30. accesskey="I">index</a></li>
  31. <li class="right" >
  32. <a href="../modindex.html" title="Global Module Index"
  33. accesskey="M">modules</a> |</li>
  34. <li class="right" >
  35. <a href="celery.result.html" title="Task Result - celery.result"
  36. accesskey="N">next</a> |</li>
  37. <li class="right" >
  38. <a href="../index.html" title="Welcome to Celery’s documentation!"
  39. accesskey="P">previous</a> |</li>
  40. <li><a href="../index.html">Celery v0.1.14 documentation</a> &raquo;</li>
  41. </ul>
  42. </div>
  43. <div class="document">
  44. <div class="documentwrapper">
  45. <div class="bodywrapper">
  46. <div class="body">
  47. <div class="section" id="module-celery.task">
  48. <h1>Tasks - celery.task<a class="headerlink" href="#module-celery.task" title="Permalink to this headline">¶</a></h1>
  49. <dl class="class">
  50. <dt id="celery.task.AsynchronousMapTask">
  51. <em class="property">
  52. 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>
  53. <dd>Task used internally by <tt class="docutils literal"><span class="pre">dmap_async</span></tt>.</dd></dl>
  54. <dl class="class">
  55. <dt id="celery.task.DeleteExpiredTaskMetaTask">
  56. <em class="property">
  57. 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>
  58. <dd><p>A periodic task that deletes expired task metadata every day.</p>
  59. <p>This runs the current backend&#8217;s cleanup() method.</p>
  60. </dd></dl>
  61. <dl class="class">
  62. <dt id="celery.task.ExecuteRemoteTask">
  63. <em class="property">
  64. 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>
  65. <dd><p>Execute arbitrary function/object.</p>
  66. <p>The object must be pickleable, so you can&#8217;t use lambdas or functions
  67. defined in the REPL.</p>
  68. <dl class="method">
  69. <dt id="celery.task.ExecuteRemoteTask.run">
  70. <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>
  71. <dd>Execute the pickled <tt class="docutils literal"><span class="pre">ser_callable</span></tt>, with <tt class="docutils literal"><span class="pre">fargs</span></tt> as positional
  72. arguments and <tt class="docutils literal"><span class="pre">fkwargs</span></tt> as keyword arguments.</dd></dl>
  73. </dd></dl>
  74. <dl class="class">
  75. <dt id="celery.task.PeriodicTask">
  76. <em class="property">
  77. 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>
  78. <dd><p>A periodic task is a task that behaves like a cron job.</p>
  79. <p>The <tt class="docutils literal"><span class="pre">run_every</span></tt> attribute defines how often the task is run (its
  80. interval), it can be either a <tt class="docutils literal"><span class="pre">datetime.timedelta</span></tt> object or a integer
  81. specifying the time in seconds.</p>
  82. <p>You have to register the periodic task in the task registry.</p>
  83. <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>
  84. <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>
  85. <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>
  86. <span class="gp">... </span> <span class="n">name</span> <span class="o">=</span> <span class="s">&quot;my_periodic_task&quot;</span>
  87. <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>
  88. <span class="gp">...</span>
  89. <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>
  90. <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>
  91. <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>
  92. <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>
  93. </pre></div>
  94. </div>
  95. </dd></dl>
  96. <dl class="class">
  97. <dt id="celery.task.Task">
  98. <em class="property">
  99. 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>
  100. <dd><p>A task that can be delayed for execution by the <tt class="docutils literal"><span class="pre">celery</span></tt> daemon.</p>
  101. <p>All subclasses of <tt class="docutils literal"><span class="pre">Task</span></tt> has to define the <tt class="docutils literal"><span class="pre">name</span></tt> attribute, which is
  102. the name of the task that can be passed to <tt class="docutils literal"><span class="pre">celery.task.delay_task</span></tt>,
  103. it also has to define the <tt class="docutils literal"><span class="pre">run</span></tt> method, which is the actual method the
  104. <tt class="docutils literal"><span class="pre">celery</span></tt> daemon executes.</p>
  105. <p>This is a simple task just logging a message,</p>
  106. <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>
  107. <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>
  108. <span class="gp">... </span> <span class="n">name</span> <span class="o">=</span> <span class="s">&quot;mytask&quot;</span>
  109. <span class="gp">...</span>
  110. <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>
  111. <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>
  112. <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>
  113. <span class="gp">... </span> <span class="n">some_arg</span><span class="p">))</span>
  114. <span class="gp">... </span> <span class="k">return</span> <span class="mf">42</span>
  115. <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>
  116. </pre></div>
  117. </div>
  118. <p>You can delay the task using the classmethod <tt class="docutils literal"><span class="pre">delay</span></tt>...</p>
  119. <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>
  120. <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>
  121. <span class="go">&#39;DONE&#39;</span>
  122. <span class="gp">&gt;&gt;&gt; </span><span class="n">result</span><span class="o">.</span><span class="n">result</span>
  123. <span class="go">42</span>
  124. </pre></div>
  125. </div>
  126. <p>...or using the <tt class="docutils literal"><span class="pre">celery.task.delay_task</span></tt> function, by passing the
  127. name of the task.</p>
  128. <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>
  129. <span class="gp">&gt;&gt;&gt; </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>
  130. </pre></div>
  131. </div>
  132. <dl class="classmethod">
  133. <dt id="celery.task.Task.delay">
  134. <em class="property">
  135. 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>
  136. <dd>Delay this task for execution by the <tt class="docutils literal"><span class="pre">celery</span></tt> daemon(s).</dd></dl>
  137. <dl class="method">
  138. <dt id="celery.task.Task.get_consumer">
  139. <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>
  140. <dd>Get a celery task message consumer.</dd></dl>
  141. <dl class="method">
  142. <dt id="celery.task.Task.get_logger">
  143. <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>
  144. <dd>Get a process-aware logger object.</dd></dl>
  145. <dl class="method">
  146. <dt id="celery.task.Task.get_publisher">
  147. <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>
  148. <dd>Get a celery task message publisher.</dd></dl>
  149. <dl class="method">
  150. <dt id="celery.task.Task.run">
  151. <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>
  152. <dd>The actual task. 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
  153. the run method, if not a <tt class="docutils literal"><span class="pre">NotImplementedError</span></tt> exception is raised.</dd></dl>
  154. </dd></dl>
  155. <dl class="class">
  156. <dt id="celery.task.TaskSet">
  157. <em class="property">
  158. 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>
  159. <dd><p>A task containing several subtasks, making it possible
  160. to track how many, or when all of the tasks are completed.</p>
  161. <blockquote>
  162. <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>
  163. <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>
  164. <span class="gp">... </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>
  165. <span class="gp">... </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>
  166. <span class="gp">... </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>
  167. </pre></div>
  168. </div>
  169. <div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">taskset_id</span><span class="p">,</span> <span class="n">subtask_ids</span> <span class="o">=</span> <span class="n">taskset</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
  170. </pre></div>
  171. </div>
  172. </blockquote>
  173. <dl class="method">
  174. <dt id="celery.task.TaskSet.iterate">
  175. <tt class="descname">iterate</tt><big>(</big><big>)</big><a class="headerlink" href="#celery.task.TaskSet.iterate" title="Permalink to this definition">¶</a></dt>
  176. <dd><p>Iterate over the results returned after calling <tt class="docutils literal"><span class="pre">run()</span></tt>.</p>
  177. <p>If any of the tasks raises an exception, the exception will
  178. be reraised by <tt class="docutils literal"><span class="pre">iterate</span></tt>.</p>
  179. </dd></dl>
  180. <dl class="method">
  181. <dt id="celery.task.TaskSet.join">
  182. <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>
  183. <dd><p>Gather the results for all of the tasks in the taskset,
  184. and return a list with them ordered by the order of which they
  185. were called.</p>
  186. <p>If any of the tasks raises an exception, the exception
  187. will be reraised by <tt class="docutils literal"><span class="pre">join</span></tt>.</p>
  188. <p>If <tt class="docutils literal"><span class="pre">timeout</span></tt> is not <tt class="xref docutils literal"><span class="pre">None</span></tt> and the operation takes
  189. longer than <tt class="docutils literal"><span class="pre">timeout</span></tt> seconds, it will raise
  190. the <a title="celery.timer.TimeoutError" class="reference external" href="celery.timer.html#celery.timer.TimeoutError"><tt class="xref docutils literal"><span class="pre">celery.timer.TimeoutError</span></tt></a> exception.</p>
  191. </dd></dl>
  192. <dl class="classmethod">
  193. <dt id="celery.task.TaskSet.map">
  194. <em class="property">
  195. 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>
  196. <dd>Distribute processing of the arguments and collect the results.</dd></dl>
  197. <dl class="classmethod">
  198. <dt id="celery.task.TaskSet.map_async">
  199. <em class="property">
  200. 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>
  201. <dd><p>Distribute processing of the arguments and collect the results
  202. asynchronously.</p>
  203. <p>Returns <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.</p>
  204. </dd></dl>
  205. <dl class="classmethod">
  206. <dt id="celery.task.TaskSet.remote_execute">
  207. <em class="property">
  208. 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>
  209. <dd>Apply <tt class="docutils literal"><span class="pre">args</span></tt> to function by distributing the args to the
  210. celery server(s).</dd></dl>
  211. <dl class="method">
  212. <dt id="celery.task.TaskSet.run">
  213. <tt class="descname">run</tt><big>(</big><big>)</big><a class="headerlink" href="#celery.task.TaskSet.run" title="Permalink to this definition">¶</a></dt>
  214. <dd><p>Run all tasks in the taskset.</p>
  215. <p>Returns a tuple with the taskset id, and a list of subtask id&#8217;s.</p>
  216. <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">RefreshFeeds</span><span class="p">([</span>
  217. <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>
  218. <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>
  219. <span class="gp">... </span><span class="p">)</span>
  220. <span class="gp">&gt;&gt;&gt; </span><span class="n">taskset_id</span><span class="p">,</span> <span class="n">subtask_ids</span> <span class="o">=</span> <span class="n">ts</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
  221. <span class="gp">&gt;&gt;&gt; </span><span class="n">taskset_id</span>
  222. <span class="go">&quot;d2c9b261-8eff-4bfb-8459-1e1b72063514&quot;</span>
  223. <span class="gp">&gt;&gt;&gt; </span><span class="n">subtask_ids</span>
  224. <span class="go">[&quot;b4996460-d959-49c8-aeb9-39c530dcde25&quot;,</span>
  225. <span class="go">&quot;598d2d18-ab86-45ca-8b4f-0779f5d6a3cb&quot;]</span>
  226. <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>
  227. <span class="gp">&gt;&gt;&gt; </span><span class="n">is_done</span><span class="p">(</span><span class="n">taskset_id</span><span class="p">)</span>
  228. <span class="go">True</span>
  229. </pre></div>
  230. </div>
  231. </dd></dl>
  232. </dd></dl>
  233. <dl class="function">
  234. <dt id="celery.task.delay_task">
  235. <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>
  236. <dd><p>Delay a task for execution by the <tt class="docutils literal"><span class="pre">celery</span></tt> daemon.</p>
  237. <div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </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>
  238. </pre></div>
  239. </div>
  240. </dd></dl>
  241. <dl class="function">
  242. <dt id="celery.task.discard_all">
  243. <tt class="descclassname">celery.task.</tt><tt class="descname">discard_all</tt><big>(</big><big>)</big><a class="headerlink" href="#celery.task.discard_all" title="Permalink to this definition">¶</a></dt>
  244. <dd><p>Discard all waiting tasks.</p>
  245. <p>This will ignore all tasks waiting for execution, and they will
  246. be deleted from the messaging server.</p>
  247. <p>Returns the number of tasks discarded.</p>
  248. </dd></dl>
  249. <dl class="function">
  250. <dt id="celery.task.dmap">
  251. <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>
  252. <dd><p>Distribute processing of the arguments and collect the results.</p>
  253. <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>
  254. <span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">operator</span>
  255. <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>
  256. <span class="go">[4, 8, 16]</span>
  257. </pre></div>
  258. </div>
  259. </dd></dl>
  260. <dl class="function">
  261. <dt id="celery.task.dmap_async">
  262. <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>
  263. <dd><p>Distribute processing of the arguments and collect the results
  264. asynchronously.</p>
  265. <p>Returns a <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.</p>
  266. <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>
  267. <span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">operator</span>
  268. <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>
  269. <span class="gp">&gt;&gt;&gt; </span><span class="n">presult</span>
  270. <span class="go">&lt;AsyncResult: 373550e8-b9a0-4666-bc61-ace01fa4f91d&gt;</span>
  271. <span class="gp">&gt;&gt;&gt; </span><span class="n">presult</span><span class="o">.</span><span class="n">status</span>
  272. <span class="go">&#39;DONE&#39;</span>
  273. <span class="gp">&gt;&gt;&gt; </span><span class="n">presult</span><span class="o">.</span><span class="n">result</span>
  274. <span class="go">[4, 8, 16]</span>
  275. </pre></div>
  276. </div>
  277. </dd></dl>
  278. <dl class="function">
  279. <dt id="celery.task.execute_remote">
  280. <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>
  281. <dd><p>Execute arbitrary function/object remotely.</p>
  282. <p>The object must be picklable, so you can&#8217;t use lambdas or functions
  283. defined in the REPL (the objects must have an associated module).</p>
  284. </dd></dl>
  285. <dl class="function">
  286. <dt id="celery.task.is_done">
  287. <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>
  288. <dd>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.</dd></dl>
  289. <dl class="function">
  290. <dt id="celery.task.mark_as_done">
  291. <tt class="descclassname">celery.task.</tt><tt class="descname">mark_as_done</tt><big>(</big><em>task_id</em>, <em>result</em><big>)</big><a class="headerlink" href="#celery.task.mark_as_done" title="Permalink to this definition">¶</a></dt>
  292. <dd>Mark task as done (executed).</dd></dl>
  293. <dl class="function">
  294. <dt id="celery.task.mark_as_failure">
  295. <tt class="descclassname">celery.task.</tt><tt class="descname">mark_as_failure</tt><big>(</big><em>task_id</em>, <em>exc</em><big>)</big><a class="headerlink" href="#celery.task.mark_as_failure" title="Permalink to this definition">¶</a></dt>
  296. <dd>Mark task as done (executed).</dd></dl>
  297. </div>
  298. </div>
  299. </div>
  300. </div>
  301. <div class="sphinxsidebar">
  302. <div class="sphinxsidebarwrapper">
  303. <h4>Previous topic</h4>
  304. <p class="topless"><a href="../index.html"
  305. title="previous chapter">Welcome to Celery&#8217;s documentation!</a></p>
  306. <h4>Next topic</h4>
  307. <p class="topless"><a href="celery.result.html"
  308. title="next chapter">Task Result - celery.result</a></p>
  309. <h3>This Page</h3>
  310. <ul class="this-page-menu">
  311. <li><a href="../sources/reference/celery.task.txt"
  312. rel="nofollow">Show Source</a></li>
  313. </ul>
  314. <div id="searchbox" style="display: none">
  315. <h3>Quick search</h3>
  316. <form class="search" action="../search.html" method="get">
  317. <input type="text" name="q" size="18" />
  318. <input type="submit" value="Go" />
  319. <input type="hidden" name="check_keywords" value="yes" />
  320. <input type="hidden" name="area" value="default" />
  321. </form>
  322. <p class="searchtip" style="font-size: 90%">
  323. Enter search terms or a module, class or function name.
  324. </p>
  325. </div>
  326. <script type="text/javascript">$('#searchbox').show(0);</script>
  327. </div>
  328. </div>
  329. <div class="clearer"></div>
  330. </div>
  331. <div class="related">
  332. <h3>Navigation</h3>
  333. <ul>
  334. <li class="right" style="margin-right: 10px">
  335. <a href="../genindex.html" title="General Index"
  336. >index</a></li>
  337. <li class="right" >
  338. <a href="../modindex.html" title="Global Module Index"
  339. >modules</a> |</li>
  340. <li class="right" >
  341. <a href="celery.result.html" title="Task Result - celery.result"
  342. >next</a> |</li>
  343. <li class="right" >
  344. <a href="../index.html" title="Welcome to Celery’s documentation!"
  345. >previous</a> |</li>
  346. <li><a href="../index.html">Celery v0.1.14 documentation</a> &raquo;</li>
  347. </ul>
  348. </div>
  349. <div class="footer">
  350. &copy; Copyright 2009, Ask Solem.
  351. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.1.
  352. </div>
  353. </body>
  354. </html>