Is there a clean way in celery for knowing whether its broker and/or the result backend are down or not?
I am using celery with RabbitMQ broker and Redis backend.
Currently, the easiest way I found is submitting a dummy task which would raise kombu.exceptions.OperationalError
when the broker is down, and redis.exceptions.ConnectionError
when the backend is down.
This feels hacky, however. Is there a better way?
After digging into the source files of Celery I ended up using the following
import celery
import kombu
import redis
try:
with celery.current_app.connection_for_write() as conn:
conn.connect()
conn.release()
print("Broker is working")
except(ConnectionError, kombu.exceptions.OperationalError):
print("Broker is down")
try:
celery.current_app.backend.get('Whatever')
print("Backend is working")
except(ConnectionError, redis.exceptions.ConnectionError):
print("Backend is down")