Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if celery beat is up and running

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?

like image 524
shinoymm Avatar asked Feb 12 '16 05:02

shinoymm


1 Answers

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

like image 83
panchicore Avatar answered Sep 21 '22 07:09

panchicore