Async callback
unknown
python
4 years ago
1.0 kB
12
Indexable
async def request(client,URL,json):
response = await client.post(URL,data=json)
return response.text
async def task(customers_synt):
number_of_json = len(customers_synt)
async with httpx.AsyncClient() as client:
for x in customers_synt:
single_dict = x.dict(exclude=generate_exclude_for_ids(model=sdv_models.CustomerSynt))
single_json = jsonable_encoder(single_dict)
api_callback_url = "http://192.168.1.112:8111/TDM/ValidationApi-Json-Type-1/"+str(single_json['customer_no'])
tasks.append[request(client,api_callback_url,single_json)]
result = await asyncio.gather(*tasks)
print(result)
@sdv_router.get("/call-validation-api1/",tags=["SDS_DEMO"])
async def call_api1_validation():
from time import time
customers_synt = await CustomerSynt.objects.select_all(follow=True).all()
start = time()
await task(customers_synt)
print("time: ", time() - start)
return {"ok":1}Editor is loading...