title: How to set custom context to a Celery Task
body: <p>I've been working with Celery and Django, and everything is going fine, except when I need to retry a failed task.</p>
  
  <p>It raises the exception and never sends the task again (according to what I see in Celery Flower)</p>
  
  <p>Here is how I declared the task</p>
  
  <pre><code># Enqueue this on "my_cool_queue", retry it no more than ten times and delay the retries by 10 seconds
  @celery.task(queue='my_cool_queue', max_retries=10, default_retry_delay=10)
  def task(arg1, arg2):
      try:
      # do some things with arg2 and arg2
      except suds.WebFault, fault:
          task.retry(exc=fault, args=[arg1, arg2], queue='my_cool_queue')
  </code></pre>
  
  <p>I'm running celery with this command</p>
  
  <pre><code>python manage.py celeryd --concurrency=2 -B -Q my_cool_queue,cron -l INFO
  </code></pre>
  
  <p>I have two queues, my_cool_queue where I put all my user-generated tasks and cron, where I have all my scheduled tasks.</p>
  
  <p>What am I missing??</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Debugging a little bit celery's retry method, I've found that it isn't retrying the task
  because it receives the default context which has the "called_directly" parameter in True</p>
  
  <p>So, the first few lines on this method are the following:</p>
  
  <pre><code> # Not in worker or emulated by (apply/always_eager),
   # so just raise the original exception.
   if request.called_directly:
       maybe_reraise()  # raise orig stack if PyErr_Occurred
       raise exc or RetryTaskError('Task can be retried', None)
  </code></pre>
  
  <p>The question might be "how can I change this in an elegant way", so I don't have to
  write directly on the task:</p>
  
  <pre><code>task.request.called_directly = False
  </code></pre>
  
  <p>Thank you very much in advance.</p>