Bird
0
0

Given this Celery task code snippet, what will be the output if the task raises a ValueError on the first run?

medium📝 component behavior Q4 of 15
Django - Celery and Background Tasks
Given this Celery task code snippet, what will be the output if the task raises a ValueError on the first run? ```python @app.task(bind=True, max_retries=3) def process_data(self): try: raise ValueError('Fail') except ValueError as exc: raise self.retry(exc=exc, countdown=10) ```
AThe task will retry infinitely without limit.
BThe task will retry up to 3 times with 10 seconds delay each.
CThe task will fail immediately without retrying.
DThe task will ignore the exception and succeed.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze retry parameters

    The task has max_retries=3 and calls self.retry on exception with countdown=10.
  2. Step 2: Understand retry behavior

    On ValueError, the task retries up to 3 times, waiting 10 seconds between tries.
  3. Final Answer:

    The task will retry up to 3 times with 10 seconds delay each. -> Option B
  4. Quick Check:

    max_retries limits retries = 3 [OK]
Quick Trick: max_retries limits retry count, countdown sets delay [OK]
Common Mistakes:
MISTAKES
  • Assuming infinite retries without max_retries
  • Thinking task fails immediately without retry
  • Believing exceptions are ignored

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes