title: How to handle exception after maximum retry exceeded in celery
body: <p>I have a following program which raise exception if number is odd and return value if it is even. Now if maximum retry is exceeded, then its raise the previous occured exception. What I want to do is that after maximum retry exceeded, I would like to log this exception. I'm little bit confused how to acheived this.
  Here is the following code:</p>
  
  <pre><code>import random
  
  from celery import Celery
  
  app = Celery('add', broker='redis://localhost:6379/0')
  
  @app.task(bind=True)
  def add(self, x, y):
      # Get a random number between 1 and 10
      num = random.randint(1, 10)
      print num # To help properly understand output
      try:
          # If number is odd, fail the task
          if num % 2:
              raise Exception()
          # If number is even, succeed the task
          else:
              return x + y
      except Exception as e:
          self.retry(countdown=2, exc=e, max_retries=1)
  </code></pre>
  
  <p>The exception is</p>
  
  <pre><code>[2015-07-31 17:47:33,681: INFO/MainProcess] Received task: add.add[64e43f81-0f80-49ac-a068-4c84c689ea16]
  [2015-07-31 17:47:33,681: WARNING/Worker-2] 7
  [2015-07-31 17:47:33,703: INFO/MainProcess] Received task: add.add[64e43f81-0f80-49ac-a068-4c84c689ea16] eta:[2015-07-31 12:17:35.692557+00:00]
  [2015-07-31 17:47:33,704: INFO/MainProcess] Task add.add[64e43f81-0f80-49ac-a068-4c84c689ea16] retry: Retry in 2s: Exception()
  [2015-07-31 17:47:36,890: WARNING/Worker-4] 3
  [2015-07-31 17:47:36,894: ERROR/MainProcess] Task add.add[64e43f81-0f80-49ac-a068-4c84c689ea16] raised unexpected: Exception()
  Traceback (most recent call last):
    File "/Users/akshar/.virtualenvs/hack/lib/python2.7/site-packages/celery/app/trace.py", line 240, in trace_task
    ...
    File "/Users/akshar/Play/Python/hack/add.py", line 15, in add
      raise Exception()
  Exception
  </code></pre>
  
  <p>Instead of this raise Exception(), I want to log it anyhow. Thanks</p>