31 lines
1.3 KiB
Python
31 lines
1.3 KiB
Python
"""Read-only, bounded live progress listener for the currently submitted test."""
|
|
import argparse
|
|
import asyncio
|
|
import json
|
|
import time
|
|
import websockets
|
|
|
|
async def watch(client):
|
|
async with websockets.connect('ws://192.168.10.51:8188/ws?clientId=' + client, max_size=2**22) as ws:
|
|
deadline = time.monotonic() + 45
|
|
while time.monotonic() < deadline:
|
|
try:
|
|
raw = await asyncio.wait_for(ws.recv(), timeout=max(0.1, deadline-time.monotonic()))
|
|
except asyncio.TimeoutError:
|
|
break
|
|
if not isinstance(raw,str):
|
|
continue
|
|
event = json.loads(raw)
|
|
kind, data = event.get('type'), event.get('data',{})
|
|
if kind == 'progress_state':
|
|
print(json.dumps({'type':kind,'data':data},ensure_ascii=False)[:2400],flush=True)
|
|
if kind in ('progress','executing','execution_error','execution_success','status'):
|
|
if kind == 'execution_error':
|
|
data = {k:data.get(k) for k in ('prompt_id','node_id','exception_type','exception_message')}
|
|
print(json.dumps({'type':kind,'data':data},ensure_ascii=False),flush=True)
|
|
|
|
if __name__ == '__main__':
|
|
p = argparse.ArgumentParser()
|
|
p.add_argument('client')
|
|
asyncio.run(watch(p.parse_args().client))
|