title: Python+Celery: Chaining jobs?
body: <p>The <a href="http://celery.readthedocs.org/en/latest/userguide/tasks.html#avoid-launching-synchronous-subtasks" rel="noreferrer">Celery documentation</a> suggests that it's a bad idea to have tasks wait on the results of other tasks… But the suggested solution (see “good” heading) leaves a something to be desired. Specifically, there's no clear way of getting the subtask's result back to the caller (also, it's kind of ugly).</p>
  
  <p>So, is there any way of “chaining” jobs, so the caller gets the result of the final job? Eg, to use the <code>add</code> example:</p>
  
  <pre><code>&gt;&gt;&gt; add3 = add.subtask(args=(3, ))
  &gt;&gt;&gt; add.delay(1, 2, callback=add3).get()
  6
  </code></pre>
  
  <p>Alternately, is it OK to return instances of Result? For example:</p>
  
  <pre><code>@task
  def add(x, y, callback=None):
      result = x + y
      if callback:
          return subtask(callback).delay(result)
      return result
  </code></pre>
  
  <p>This would let the result of the “final” job in the chain could be retrived with a simple:</p>
  
  <pre><code>result = add(1, 2, callback=add3).delay()
  while isinstance(result, Result):
      result = result.get()
  print "result:", result
  </code></pre>