worker-manager.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:worker-manager 作者: nebula-orchestrator 项目源码 文件源码
def rabbit_work_function(ch, method, properties, body):
    try:
        # check the message body to get the needed order
        app_json = loads(body)
        # if it's blank stop containers and kill worker-manger container
        if len(app_json) == 0:
            stop_containers(app_json)
            print "got a blank massage from rabbit - likely app wasn't created in nebula API yet, dropping container"
            os._exit(2)
        # elif it's stopped stop containers
        elif app_json["command"] == "stop":
            stop_containers(app_json)
        # if it's start start containers
        elif app_json["command"] == "start":
            start_containers(app_json, False, registry_auth_user, registry_auth_password, registry_host)
        # if it's roll rolling restart containers
        elif app_json["command"] == "roll":
            roll_containers(app_json, registry_auth_user, registry_auth_password, registry_host)
        # elif restart containers
        else:
            restart_containers(app_json, registry_auth_user, registry_auth_password, registry_host)
        # ack message
        rabbit_ack(ch, method)
    except pika.exceptions.ConnectionClosed as e:
        print >> sys.stderr, e
        print "lost rabbitmq connection mid transfer - dropping container to be on the safe side"
        os._exit(2)


# recursive so it will always keep trying to reconnect to rabbit in case of any connection issues
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号