Check if celery beat is up and running

shinoymm picture shinoymm · Feb 12, 2016 · Viewed 13.1k times · Source

In my Django project, I use Celery and Rabbitmq to run tasks in background. I am using celery beat scheduler to run periodic tasks. How can i check if celery beat is up and running, programmatically?

Answer

panchicore picture panchicore · Jul 25, 2018

Make a task to HTTP requests to a Ping URL at regular intervals. When the URL is not pinged on time, the URL monitor will send you an alert.

import requests
from yourapp.celery_config import app

@app.task
def ping():
    print '[healthcheck] pinging alive status...'
    # healthchecks.io works for me:
    requests.post("https://hchk.io/6466681c-7708-4423-adf0-XXXXXXXXX")

This celery periodic task is scheduled to run every minute, if it doesn't hit the ping, your beat service is down*, the monitor will kick in your mail (or webhook so you can zapier it to get mobile push notifications as well).

celery -A yourapp.celery_config beat -S djcelery.schedulers.DatabaseScheduler

*or overwhelmed, you should track tasks saturation, this is a nightmare with Celery and should be detected and addressed properly, happens frequently when the workers are busy with blocking tasks that would need optimization