Monitor Django Celery Tasks with CronRabbit
DjangoThe Problem
Django projects using Celery Beat for periodic tasks can experience silent failures when workers are down, Redis is unavailable, or tasks exhaust retries.
The Solution
Add CronRabbit pings inside your Celery task functions. Each periodic task gets its own monitor.
Pattern
Add monitoring inside the @shared_task decorated function, not in the Beat configuration. This verifies actual execution, not just scheduling.
Code Examples
Django Celery task with monitoring
Pythonfrom celery import shared_task
import requests
@shared_task(bind=True, max_retries=3)
def generate_daily_report(self):
PING = "https://ping.cronrabbit.com/your-id"
requests.get(f"{PING}/start", timeout=5)
try:
from myapp.services import ReportService
ReportService().generate()
requests.get(PING, timeout=5)
except Exception as exc:
requests.get(f"{PING}/fail", timeout=5)
raise self.retry(exc=exc)