celery.execute.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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>Executing Tasks - celery.execute &mdash; Celery v0.4.13 (stable) documentation</title>
  7. <link rel="stylesheet" href="../static/nature.css" type="text/css" />
  8. <link rel="stylesheet" href="../static/pygments.css" type="text/css" />
  9. <script type="text/javascript">
  10. var DOCUMENTATION_OPTIONS = {
  11. URL_ROOT: '../',
  12. VERSION: '0.4.13 (stable)',
  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.4.13 (stable) 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="Defining Tasks - celery.task.base" href="celery.task.base.html" />
  24. </head>
  25. <body>
  26. <div class="related">
  27. <h3>Navigation</h3>
  28. <ul>
  29. <li class="right" style="margin-right: 10px">
  30. <a href="../genindex.html" title="General Index"
  31. accesskey="I">index</a></li>
  32. <li class="right" >
  33. <a href="../modindex.html" title="Global Module Index"
  34. accesskey="M">modules</a> |</li>
  35. <li class="right" >
  36. <a href="celery.result.html" title="Task Result - celery.result"
  37. accesskey="N">next</a> |</li>
  38. <li class="right" >
  39. <a href="celery.task.base.html" title="Defining Tasks - celery.task.base"
  40. accesskey="P">previous</a> |</li>
  41. <li><a href="../index.html">Celery v0.4.13 (stable) documentation</a> &raquo;</li>
  42. <li><a href="index.html" accesskey="U">Module API Reference</a> &raquo;</li>
  43. </ul>
  44. </div>
  45. <div class="document">
  46. <div class="documentwrapper">
  47. <div class="bodywrapper">
  48. <div class="body">
  49. <div class="section" id="module-celery.execute">
  50. <h1>Executing Tasks - celery.execute<a class="headerlink" href="#module-celery.execute" title="Permalink to this headline">¶</a></h1>
  51. <dl class="function">
  52. <dt id="celery.execute.apply">
  53. <tt class="descclassname">celery.execute.</tt><tt class="descname">apply</tt><big>(</big><em>task</em>, <em>args</em>, <em>kwargs</em>, <em>**ignored</em><big>)</big><a class="headerlink" href="#celery.execute.apply" title="Permalink to this definition">¶</a></dt>
  54. <dd><p>Apply the task locally.</p>
  55. <p>This will block until the task completes, and returns a
  56. <a title="celery.result.EagerResult" class="reference external" href="celery.result.html#celery.result.EagerResult"><tt class="xref docutils literal"><span class="pre">celery.result.EagerResult</span></tt></a> instance.</p>
  57. </dd></dl>
  58. <dl class="function">
  59. <dt id="celery.execute.apply_async">
  60. <tt class="descclassname">celery.execute.</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>countdown=None</em>, <em>eta=None</em>, <em>**opts</em><big>)</big><a class="headerlink" href="#celery.execute.apply_async" title="Permalink to this definition">¶</a></dt>
  61. <dd><p>Run a task asynchronously by the celery daemon(s).</p>
  62. <table class="docutils field-list" frame="void" rules="none">
  63. <col class="field-name" />
  64. <col class="field-body" />
  65. <tbody valign="top">
  66. <tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  67. <li><em>task</em> &#8211; The task to run (a callable object, or a <tt class="xref docutils literal"><span class="pre">Task</span></tt>
  68. instance</li>
  69. <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>
  70. <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>
  71. <li><em>countdown</em> &#8211; Number of seconds into the future that the task should
  72. execute. Defaults to immediate delivery (Do not confuse that with
  73. the <tt class="docutils literal"><span class="pre">immediate</span></tt> setting, they are unrelated).</li>
  74. <li><em>eta</em> &#8211; A <tt class="xref docutils literal"><span class="pre">datetime.datetime</span></tt> object that describes the
  75. absolute time when the task should execute. May not be specified
  76. if <tt class="docutils literal"><span class="pre">countdown</span></tt> is also supplied. (Do not confuse this with the
  77. <tt class="docutils literal"><span class="pre">immediate</span></tt> setting, they are unrelated).</li>
  78. <li><em>routing_key</em> &#8211; The routing key used to route the task to a worker
  79. server.</li>
  80. <li><em>immediate</em> &#8211; Request immediate delivery. Will raise an exception
  81. if the task cannot be routed to a worker immediately.
  82. (Do not confuse this parameter with the <tt class="docutils literal"><span class="pre">countdown</span></tt> and <tt class="docutils literal"><span class="pre">eta</span></tt>
  83. settings, as they are unrelated).</li>
  84. <li><em>mandatory</em> &#8211; Mandatory routing. Raises an exception if there&#8217;s
  85. no running workers able to take on this task.</li>
  86. <li><em>connection</em> &#8211; Re-use existing AMQP connection.
  87. The <tt class="docutils literal"><span class="pre">connect_timeout</span></tt> argument is not respected if this is set.</li>
  88. <li><em>connect_timeout</em> &#8211; The timeout in seconds, before we give up
  89. on establishing a connection to the AMQP server.</li>
  90. <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>
  91. </ul>
  92. </td>
  93. </tr>
  94. </tbody>
  95. </table>
  96. </dd></dl>
  97. <dl class="function">
  98. <dt id="celery.execute.delay_task">
  99. <tt class="descclassname">celery.execute.</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.execute.delay_task" title="Permalink to this definition">¶</a></dt>
  100. <dd><p>Delay a task for execution by the <tt class="docutils literal"><span class="pre">celery</span></tt> daemon.</p>
  101. <table class="docutils field-list" frame="void" rules="none">
  102. <col class="field-name" />
  103. <col class="field-body" />
  104. <tbody valign="top">
  105. <tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  106. <li><em>task_name</em> &#8211; the name of a task registered in the task registry.</li>
  107. <li><em>*args</em> &#8211; positional arguments to pass on to the task.</li>
  108. <li><em>**kwargs</em> &#8211; keyword arguments to pass on to the task.</li>
  109. </ul>
  110. </td>
  111. </tr>
  112. <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>
  113. <tr><td>&nbsp;</td><td class="field-body"><p class="first">exception if no such task
  114. has been registered in the task registry.</p>
  115. </td>
  116. </tr>
  117. <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>
  118. </td>
  119. </tr>
  120. </tbody>
  121. </table>
  122. <p>Example</p>
  123. <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>
  124. <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>
  125. <span class="go">True</span>
  126. <span class="gp">&gt;&gt;&gt; </span><span class="n">r</span><span class="o">.</span><span class="n">result</span>
  127. <span class="go">&quot;Record was updated&quot;</span>
  128. </pre></div>
  129. </div>
  130. </dd></dl>
  131. </div>
  132. </div>
  133. </div>
  134. </div>
  135. <div class="sphinxsidebar">
  136. <div class="sphinxsidebarwrapper">
  137. <h4>Previous topic</h4>
  138. <p class="topless"><a href="celery.task.base.html"
  139. title="previous chapter">Defining Tasks - celery.task.base</a></p>
  140. <h4>Next topic</h4>
  141. <p class="topless"><a href="celery.result.html"
  142. title="next chapter">Task Result - celery.result</a></p>
  143. <h3>This Page</h3>
  144. <ul class="this-page-menu">
  145. <li><a href="../sources/reference/celery.execute.txt"
  146. rel="nofollow">Show Source</a></li>
  147. </ul>
  148. <div id="searchbox" style="display: none">
  149. <h3>Quick search</h3>
  150. <form class="search" action="../search.html" method="get">
  151. <input type="text" name="q" size="18" />
  152. <input type="submit" value="Go" />
  153. <input type="hidden" name="check_keywords" value="yes" />
  154. <input type="hidden" name="area" value="default" />
  155. </form>
  156. <p class="searchtip" style="font-size: 90%">
  157. Enter search terms or a module, class or function name.
  158. </p>
  159. </div>
  160. <script type="text/javascript">$('#searchbox').show(0);</script>
  161. </div>
  162. </div>
  163. <div class="clearer"></div>
  164. </div>
  165. <div class="related">
  166. <h3>Navigation</h3>
  167. <ul>
  168. <li class="right" style="margin-right: 10px">
  169. <a href="../genindex.html" title="General Index"
  170. >index</a></li>
  171. <li class="right" >
  172. <a href="../modindex.html" title="Global Module Index"
  173. >modules</a> |</li>
  174. <li class="right" >
  175. <a href="celery.result.html" title="Task Result - celery.result"
  176. >next</a> |</li>
  177. <li class="right" >
  178. <a href="celery.task.base.html" title="Defining Tasks - celery.task.base"
  179. >previous</a> |</li>
  180. <li><a href="../index.html">Celery v0.4.13 (stable) documentation</a> &raquo;</li>
  181. <li><a href="index.html" >Module API Reference</a> &raquo;</li>
  182. </ul>
  183. </div>
  184. <div class="footer">
  185. &copy; Copyright 2009, Ask Solem.
  186. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.2.
  187. </div>
  188. </body>
  189. </html>