Detect whether Celery is Available/Running

后端 未结 7 546
遥遥无期
遥遥无期 2020-12-04 12:09

I\'m using Celery to manage asynchronous tasks. Occasionally, however, the celery process goes down which causes none of the tasks to get executed. I would like to be able t

7条回答
  •  情话喂你
    2020-12-04 12:45

    The following worked for me:

    import socket
    from kombu import Connection
    
    celery_broker_url = "amqp://localhost"
    
    try:
        conn = Connection(celery_broker_url)
        conn.ensure_connection(max_retries=3)
    except socket.error:
        raise RuntimeError("Failed to connect to RabbitMQ instance at {}".format(celery_broker_url))
    

提交回复
热议问题