[英]How to get the status of celery broker and backend?
celery 中是否有一种干净的方法来了解其代理和/或结果后端是否已关闭?
我将 celery 与 RabbitMQ 经纪人和 Redis 后端一起使用。
目前,我发现最简单的方法是提交一个虚拟任务,当代理关闭时会引发kombu.exceptions.OperationalError
,当后端redis.exceptions.ConnectionError
时会引发 redis.exceptions.ConnectionError。
然而,这感觉很老套。 有没有更好的办法?
在深入了解Celery的源文件后,我最终使用了以下内容
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")
它不是处理检查 rabbitmq 连接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.