"magic_pdf/vscode:/vscode.git/clone" did not exist on "6750b6ca40b472d70682c66b04fe682c2d85eb58"
Unverified Commit 801523fc authored by Marvin Meiers's avatar Marvin Meiers
Browse files

symphony: send simulator ouput lines to backend

parent b41d6b88
......@@ -428,3 +428,23 @@ class RunnerClient:
}
async with self.put(url=f"/update_run/{run_id}", json=obj) as resp:
ret = await resp.json()
async def send_out(
self,
run_id: int,
simulator: str,
stderr: bool,
output: list[str],
) -> None:
objs = []
for line in output:
obj = {
"run_id": run_id,
"simulator": simulator,
"stderr": stderr,
"output": line,
}
objs.append[obj]
async with self.post(url=f"/{run_id}/console", json=objs) as resp:
ret = await resp.json()
......@@ -37,18 +37,26 @@ verbose = True
# TODO: FIXME, create a custom listener for the runner to register + create backend endpoint to update the output etc.
async def periodically_update(rc: client.RunnerClient, run_id: int,
listeners: list[command_executor.LegacyOutputListener]) -> None:
listeners: list[tuple[str, simulation_executor.SimulationSimpleRunner]]) -> None:
try:
while True:
all_out: list[str] = []
sim_outs: list[tuple[str, bool, str]] = []
for listener in listeners:
all_out.extend(listener.merged_output)
listener.merged_output = []
all_out.extend(listener[1].merged_output)
listener[1].merged_output = []
sim_outs.append((listener[0], False, listener[1].stdout))
sim_outs.append((listener[0], True, listener[1].stderr))
listener[1].stdout = []
listener[1].stderr = []
if len(all_out) > 0:
print(all_out)
#print(all_out)
await rc.update_run(run_id, "running", json.dumps(all_out))
for sim_out in sim_outs:
await rc.send_out(run_id, sim_out[0], sim_out[1], sim_out[2])
await asyncio.sleep(0.5)
except asyncio.CancelledError:
......@@ -66,7 +74,7 @@ async def run_instantiation(sc: client.SimBricksClient, rc: client.RunnerClient,
for sim in inst.simulation.all_simulators():
listener = command_executor.LegacyOutputListener()
runner.add_listener(sim, listener)
listeners.append(listener)
listeners.append((sim.name, listener))
update_task = asyncio.create_task(periodically_update(rc=rc, run_id=run_id, listeners=listeners))
output = await runner.run()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment