Bird
0
0

Why is it important to use the @celery_app.task(bind=True) decorator when defining tasks that need to retry on failure?

hard📝 Conceptual Q10 of 15
Flask - Background Tasks
Why is it important to use the @celery_app.task(bind=True) decorator when defining tasks that need to retry on failure?
ABecause it automatically retries the task without extra code.
BBecause it makes the task run synchronously.
CBecause it passes the task instance as the first argument, allowing access to retry methods.
DBecause it disables retries and forces failure.
Step-by-Step Solution
Solution:
  1. Step 1: Understand bind=True effect

    It passes the task instance as the first argument (usually self), enabling use of methods like self.retry().
  2. Step 2: Clarify retry control

    Retries are not automatic; you must call self.retry() inside the task, which requires binding.
  3. Final Answer:

    Because it passes the task instance as the first argument, allowing access to retry methods. -> Option C
  4. Quick Check:

    bind=True gives task instance for retries [OK]
Quick Trick: Use bind=True to access self.retry() in tasks [OK]
Common Mistakes:
MISTAKES
  • Thinking retries happen automatically without code
  • Confusing bind with synchronous execution
  • Assuming bind disables retries

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes