Detect whether Celery is Available/Running

后端 未结 7 556
遥遥无期
遥遥无期 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:32

    From the documentation of celery 4.2:

    from your_celery_app import app
    
    
    def get_celery_worker_status():
        i = app.control.inspect()
        availability = i.ping()
        stats = i.stats()
        registered_tasks = i.registered()
        active_tasks = i.active()
        scheduled_tasks = i.scheduled()
        result = {
            'availability': availability,
            'stats': stats,
            'registered_tasks': registered_tasks,
            'active_tasks': active_tasks,
            'scheduled_tasks': scheduled_tasks
        }
        return result
    

    of course you could/should improve the code with error handling...

提交回复
热议问题