celery.execute.html 10 KB

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