Bird
0
0

You want to define a Celery task that retries automatically up to 3 times if it fails. Which addition to the task definition is correct?

hard📝 Conceptual Q8 of 15
Django - Celery and Background Tasks
You want to define a Celery task that retries automatically up to 3 times if it fails. Which addition to the task definition is correct?
AAdd <code>max_retries=3</code> as a function argument
BUse <code>autoretry_for=(Exception,), retry_kwargs={'max_retries': 3}</code> in the @shared_task decorator
CCall <code>self.retry()</code> inside the task without decorator changes
DSet <code>retry=True</code> in the Celery config file only
Step-by-Step Solution
Solution:
  1. Step 1: Recall how to enable automatic retries

    Celery supports autoretry_for and retry_kwargs in the task decorator to configure retries.
  2. Step 2: Identify correct usage

    Use autoretry_for=(Exception,), retry_kwargs={'max_retries': 3} in the @shared_task decorator correctly uses autoretry_for with max_retries in retry_kwargs.
  3. Final Answer:

    Use autoretry_for=(Exception,), retry_kwargs={'max_retries': 3} in the @shared_task decorator -> Option B
  4. Quick Check:

    Automatic retries configured via decorator args [OK]
Quick Trick: Use autoretry_for and retry_kwargs in decorator for retries [OK]
Common Mistakes:
MISTAKES
  • Trying to pass max_retries as function argument
  • Forgetting to configure decorator for retries
  • Assuming config file alone handles retries

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes