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')
评论列表
文章目录