Monitor Celery Beat Scheduled Tasks with CronRabbit
PythonThe Problem
Celery Beat triggers periodic tasks, but if the worker is down, the queue is full, or the task silently fails, you won't know until the damage is done.
The Solution
Add a CronRabbit ping inside your Celery task function. The heartbeat confirms the task actually ran to completion, not just that it was scheduled.
The Celery Beat Blind Spot
Celery Beat faithfully enqueues tasks on schedule, but that doesn't mean they execute. The worker might be offline, OOM-killed, or stuck on a previous task. CronRabbit monitors the actual execution, not the schedule.
Integration Pattern
Add a ping at the end of your @app.task function. Use requests.get() with a short timeout. For critical tasks, send /start at the beginning to track duration.
Handling Retries
If your Celery task has autoretry_for enabled, place the success ping only in the final successful path. Failed attempts should send /fail to get early warning.
Code Examples
Celery Beat task with monitoring
Pythonfrom celery import Celery
import requests
app = Celery("tasks")
PING_URL = "https://ping.cronrabbit.com/your-monitor-id"
@app.task(bind=True, max_retries=3)
def nightly_report(self):
requests.get(f"{PING_URL}/start", timeout=5)
try:
generate_report()
send_emails()
requests.get(PING_URL, timeout=5)
except Exception as exc:
requests.get(f"{PING_URL}/fail", timeout=5)
raise self.retry(exc=exc)