Performance: Celery installation and setup
This affects backend task processing speed and responsiveness of the Django app by offloading work from the main request cycle.
Jump into concepts and practice - no test required
from celery import shared_task @shared_task def send_mass_email(): # Long running task pass # In view send_mass_email.delay() return HttpResponse('Email sending started')
def send_email(request): # Long running task send_mass_email() return HttpResponse('Email sent')
| Pattern | Backend Blocking | User Response Delay | Resource Usage | Verdict |
|---|---|---|---|---|
| Synchronous task in view | Blocks main thread | High delay | High CPU during request | [X] Bad |
| Asynchronous Celery task | No blocking | Minimal delay | Offloaded to worker | [OK] Good |
@shared_task
def add(x, y):
return x + y
result = add.delay(4, 5)
print(result.get(timeout=10))
What will be printed when this code runs correctly?from celery import Celery
app = Celery('proj')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
But your tasks are not running. What is the most likely mistake?celery.py file?