Bird
0
0

You want to configure Celery in your Django project to use Redis as the broker and ensure tasks are auto-discovered. Which of the following is the correct minimal setup in your celery.py file?

hard📝 Application Q15 of 15
Django - Celery and Background Tasks
You want to configure Celery in your Django project to use Redis as the broker and ensure tasks are auto-discovered. Which of the following is the correct minimal setup in your celery.py file?
Afrom celery import Celery app = Celery('proj') app.config_from_object('settings') app.autodiscover_tasks()
Bfrom celery import Celery app = Celery('proj') app.config_from_object('django.conf:settings', namespace='CELERY') app.autodiscover_tasks()
Cfrom celery import Celery app = Celery('proj', broker='redis://localhost:6379/0') app.autodiscover_tasks()
Dfrom celery import Celery app = Celery('proj') app.broker_url = 'redis://localhost:6379/0' app.autodiscover_tasks()
Step-by-Step Solution
Solution:
  1. Step 1: Set broker URL directly in Celery instance

    from celery import Celery app = Celery('proj', broker='redis://localhost:6379/0') app.autodiscover_tasks() correctly passes Redis broker URL when creating Celery app, which is a minimal working setup.
  2. Step 2: Evaluate other options

    The first uses an invalid path to settings ('settings' instead of 'django.conf:settings'); the second requires defining CELERY_BROKER_URL in Django settings.py first; the third is correct syntax-wise but setting broker_url attribute after creation is less minimal than passing in constructor.
  3. Final Answer:

    from celery import Celery app = Celery('proj', broker='redis://localhost:6379/0') app.autodiscover_tasks() -> Option C
  4. Quick Check:

    Broker URL in constructor = from celery import Celery app = Celery('proj', broker='redis://localhost:6379/0') app.autodiscover_tasks() [OK]
Quick Trick: Pass broker URL directly to Celery constructor for quick setup [OK]
Common Mistakes:
MISTAKES
  • Setting broker_url attribute instead of passing in constructor
  • Misconfiguring config_from_object with wrong settings path
  • Omitting broker URL causing connection failure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes