def start_job_processor():
    print('start_job_processor')
    while 1:
        print('1')
        try:
            res = requests.get(((lowDefine.FRONT_SERVER_SERVER_URL + '/ge/sch/gm/fs/dispatched-queue/policys/') + lowDefine.SELF_POLICY_NAME))
        except:
            print('wait front server to run', lowDefine.FRONT_SERVER_SERVER_URL)
            time.sleep(5)
            continue
        if (res.status_code == 200):
            print('2')
            request_data_dic = json.loads(res.json())
            print('request_data_dic', request_data_dic)
            GE_Request_Job = GLowLatencyPriority_Job(request_data_dic)
            print('3')
            "\n            return values \n                'apply_success' : apply is success\n                'process_success' :\n                'process_fail': raise error in process(apply or wait consumer, request latency) \n                'apply_fail' : apply is fail \n            "
            is_whole_process_status = None
            for item in GE_Request_Job.targetClusters:
                print('type(item)', type(item), item)
                if ((type(item).__name__ == 'list') and (len(item) > 1)):
                    r = GE_Request_Job.request_clusters_latency_from_clusterAgent(item)
                    if (r == 'process_fail'):
                        print('internal error : request_clusters_latency_from_clusterAgent')
                        continue
                    (r, clusters) = GE_Request_Job.wait_request_clusters_latency_from_clusterAgent()
                    if (r == 'process_fail'):
                        print('internal error : wait_request_clusters_latency_from_clusterAgent')
                        continue
                    for t_cluster in clusters:
                        r = GE_Request_Job.apply_yaml_to_ClusterAgent(t_cluster)
                        if (r == 'process_fail'):
                            print('internal error : apply_yaml_to_ClusterAgent')
                            continue
                        r = GE_Request_Job.wait_apply_yaml_to_ClusterAgent()
                        if (r == 'process_fail'):
                            print('internal error : wait_apply_yaml_to_ClusterAgent')
                            continue
                        elif ((r == 'apply_success') or (r == 'cancel')):
                            print('---pply_success or cancel', r)
                            is_whole_process_status = r
                            break
                        elif (r == 'apply_fail'):
                            is_whole_process_status = r
                            continue
                    if ((r == 'apply_success') or (r == 'cancel')):
                        break
                else:
                    r = GE_Request_Job.apply_yaml_to_ClusterAgent(item)
                    if (r == 'process_fail'):
                        print('internal error : apply_yaml_to_ClusterAgent')
                        continue
                    r = GE_Request_Job.wait_apply_yaml_to_ClusterAgent()
                    if (r == 'process_fail'):
                        print('internal error : wait_apply_yaml_to_ClusterAgent')
                        continue
                    elif ((r == 'apply_success') or (r == 'cancel')):
                        is_whole_process_status = r
                        print('apply_success or cancel:', r)
                        break
                    elif (r == 'apply_fail'):
                        is_whole_process_status = r
                        print('apply_fail')
                        continue
            print('==============')
            if (is_whole_process_status == 'apply_fail'):
                requests.put((((lowDefine.FRONT_SERVER_SERVER_URL + '/ge/sch/gm/fs/dispatched-queue/') + GE_Request_Job.requestID) + '/status/failed'))
            elif (is_whole_process_status == 'apply_success'):
                requests.put((((lowDefine.FRONT_SERVER_SERVER_URL + '/ge/sch/gm/fs/dispatched-queue/') + GE_Request_Job.requestID) + '/status/completed'))
            elif (is_whole_process_status == 'cancel'):
                requests.put((((lowDefine.FRONT_SERVER_SERVER_URL + '/ge/sch/gm/fs/dispatched-queue/') + GE_Request_Job.requestID) + '/status/canceled'))
            else:
                requests.put((((lowDefine.FRONT_SERVER_SERVER_URL + '/ge/sch/gm/fs/dispatched-queue/') + GE_Request_Job.requestID) + '/status/canceled'))
        else:
            print('despatched queue is empty')
            time.sleep(5)
            continue
def start_job_processor():
    print('start_job_processor')
    while 1:
        print('1')
        try:
            res = requests.get(((lowDefine.FRONT_SERVER_SERVER_URL + '/ge/sch/gm/fs/dispatched-queue/policys/') + lowDefine.SELF_POLICY_NAME))
        except:
            print('wait front server to run', lowDefine.FRONT_SERVER_SERVER_URL)
            time.sleep(5)
            continue
        if (res.status_code == 200):
            print('2')
            request_data_dic = json.loads(res.json())
            print('request_data_dic', request_data_dic)
            GE_Request_Job = GLowLatencyPriority_Job(request_data_dic)
            print('3')
            "\n            return values \n                'apply_success' : apply is success\n                'process_success' :\n                'process_fail': raise error in process(apply or wait consumer, request latency) \n                'apply_fail' : apply is fail \n            "
            is_whole_process_status = None
            for item in GE_Request_Job.targetClusters:
                print('type(item)', type(item), item)
                if ((type(item).__name__ == 'list') and (len(item) > 1)):
                    r = GE_Request_Job.request_clusters_latency_from_clusterAgent(item)
                    if (r == 'process_fail'):
                        print('internal error : request_clusters_latency_from_clusterAgent')
                        continue
                    (r, clusters) = GE_Request_Job.wait_request_clusters_latency_from_clusterAgent()
                    if (r == 'process_fail'):
                        print('internal error : wait_request_clusters_latency_from_clusterAgent')
                        continue
                    for t_cluster in clusters:
                        r = GE_Request_Job.apply_yaml_to_ClusterAgent(t_cluster)
                        if (r == 'process_fail'):
                            print('internal error : apply_yaml_to_ClusterAgent')
                            continue
                        r = GE_Request_Job.wait_apply_yaml_to_ClusterAgent()
                        if (r == 'process_fail'):
                            print('internal error : wait_apply_yaml_to_ClusterAgent')
                            continue
                        elif ((r == 'apply_success') or (r == 'cancel')):
                            print('---pply_success or cancel', r)
                            is_whole_process_status = r
                            break
                        elif (r == 'apply_fail'):
                            is_whole_process_status = r
                            continue
                    if ((r == 'apply_success') or (r == 'cancel')):
                        break
                else:
                    r = GE_Request_Job.apply_yaml_to_ClusterAgent(item)
                    if (r == 'process_fail'):
                        print('internal error : apply_yaml_to_ClusterAgent')
                        continue
                    r = GE_Request_Job.wait_apply_yaml_to_ClusterAgent()
                    if (r == 'process_fail'):
                        print('internal error : wait_apply_yaml_to_ClusterAgent')
                        continue
                    elif ((r == 'apply_success') or (r == 'cancel')):
                        is_whole_process_status = r
                        print('apply_success or cancel:', r)
                        break
                    elif (r == 'apply_fail'):
                        is_whole_process_status = r
                        print('apply_fail')
                        continue
            print('==============')
            if (is_whole_process_status == 'apply_fail'):
                requests.put((((lowDefine.FRONT_SERVER_SERVER_URL + '/ge/sch/gm/fs/dispatched-queue/') + GE_Request_Job.requestID) + '/status/failed'))
            elif (is_whole_process_status == 'apply_success'):
                requests.put((((lowDefine.FRONT_SERVER_SERVER_URL + '/ge/sch/gm/fs/dispatched-queue/') + GE_Request_Job.requestID) + '/status/completed'))
            elif (is_whole_process_status == 'cancel'):
                requests.put((((lowDefine.FRONT_SERVER_SERVER_URL + '/ge/sch/gm/fs/dispatched-queue/') + GE_Request_Job.requestID) + '/status/canceled'))
            else:
                requests.put((((lowDefine.FRONT_SERVER_SERVER_URL + '/ge/sch/gm/fs/dispatched-queue/') + GE_Request_Job.requestID) + '/status/canceled'))
        else:
            print('despatched queue is empty')
            time.sleep(5)
            continue