demos.py 文件源码

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

项目:logistics-wizard-controller 作者: IBM-Cloud 项目源码 文件源码
def load_admin_data():
    """
    Load all data relative to the currently logged in user

    :return: {
        "shipments": [{Shipments}],
        "retailers": [{Retailer}],
        "distribution_centers": [{Distribution Center}]
    }
    """

    # Specify functions and corresponding arguments to call to retrieve ERP data
    loopback_token = g.auth['loopback_token']
    erp_calls = [(shipment_service.get_shipments, loopback_token),
                 (distribution_center_service.get_distribution_centers, loopback_token),
                 (retailer_service.get_retailers, loopback_token)]
    pool = Pool(processes=len(erp_calls))

    # Asynchronously make calls and then wait on all processes to finish
    try:
        results = pool.map(async_helper, erp_calls)
    except Exception as e:
        raise APIException('Error retrieving admin data view', internal_details=str(e))
    pool.close()
    pool.join()

    # Send back serialized results to client
    return Response(json.dumps({
                        "shipments": json.loads(results[0]),
                        "distribution-centers": json.loads(results[1]),
                        "retailers": json.loads(results[2])
                    }),
                    status=200,
                    mimetype='application/json')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号