xbackend/ck_test.py
2021-05-12 16:38:03 +08:00

36 lines
938 B
Python

from datetime import datetime
import asyncio
from aioch import Client
from core.config import settings
async def exec_progress():
client = Client('119.29.176.224')
progress = await client.execute_with_progress('show databases')
timeout = 20
started_at = datetime.now()
async for num_rows, total_rows in progress:
done = num_rows / total_rows if total_rows else total_rows
now = datetime.now()
# Cancel query if it takes more than 20 seconds to process 50% of rows.
if (now - started_at).total_seconds() > timeout and done < 0.5:
await client.cancel()
break
else:
rv = await progress.get_result()
print(rv)
async def exec_no_progress():
client = Client(**settings.CK_CONFIG)
rv = await client.execute('show databases')
print(rv)
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait([exec_no_progress()]))