"git@developer.sourcefind.cn:gaoqiong/composable_kernel.git" did not exist on "ae5e5181aaa4a4f8587086bea262c3db4c3a9ba6"
Unverified Commit b4eb3796 authored by Jakob Görgen's avatar Jakob Görgen
Browse files

symphony/client: runner event api fixes + fetch and filter for runs

parent 84117926
...@@ -362,7 +362,7 @@ class SimBricksClient: ...@@ -362,7 +362,7 @@ class SimBricksClient:
break break
last_run = run last_run = run
await asyncio.sleep(0.5) await asyncio.sleep(3)
console.log(f"Run {run_id} finished") console.log(f"Run {run_id} finished")
...@@ -411,6 +411,13 @@ class RunnerClient: ...@@ -411,6 +411,13 @@ class RunnerClient:
async with self._ns_client.post(url=self._build_prefix(url=url), data=data, **kwargs) as resp: async with self._ns_client.post(url=self._build_prefix(url=url), data=data, **kwargs) as resp:
yield resp yield resp
@contextlib.asynccontextmanager
async def delete(
self, url: str, data: typing.Any = None, **kwargs: typing.Any
) -> typing.AsyncIterator[aiohttp.ClientResponse]:
async with self._ns_client.delete(url=self._build_prefix(url=url), data=data, **kwargs) as resp:
yield resp
@contextlib.asynccontextmanager @contextlib.asynccontextmanager
async def put( async def put(
self, url: str, data: typing.Any = None, **kwargs: typing.Any self, url: str, data: typing.Any = None, **kwargs: typing.Any
...@@ -431,31 +438,35 @@ class RunnerClient: ...@@ -431,31 +438,35 @@ class RunnerClient:
async with self._ns_client.post(url=f"/runners", json=obj) as resp: async with self._ns_client.post(url=f"/runners", json=obj) as resp:
return await resp.json() return await resp.json()
async def create_runner_event(self, runner_id: int, action: str, run_id: int | None) -> dict: async def create_runner_event(self, action: str, run_id: int | None) -> dict:
obj = {"runner_id": runner_id, "action": action, "run_id": run_id} obj = {"runner_id": self._runner_id, "action": action, "run_id": run_id}
async with self._ns_client.post(url=f"/runners/{runner_id}/events", json=obj) as resp: async with self.post(url=f"/events", json=obj) as resp:
return await resp.json() return await resp.json()
async def delete_runner_event(self, event_id: int) -> None:
async with self.delete(url=f"/events/{event_id}") as resp:
await resp.json()
async def update_runner_event( async def update_runner_event(
self, runner_id: int, event_id: int, action: str | None, run_id: int | None, event_status: str | None self, event_id: int, action: str | None, run_id: int | None, event_status: str | None
) -> dict: ) -> dict:
obj = { obj = {
"id": event_id, "id": event_id,
"runner_id": runner_id, "runner_id": self._runner_id,
"action": action, "action": action,
"run_id": run_id, "run_id": run_id,
"event_status": event_status, "event_status": event_status,
} }
obj = utils_base.filter_None_dict(to_filter=obj) obj = utils_base.filter_None_dict(to_filter=obj)
async with self._ns_client.put(url=f"/runners/{runner_id}/events", json=obj) as resp: async with self.put(url=f"/events", json=obj) as resp:
return await resp.json() return await resp.json()
async def get_events( async def get_events(
self, runner_id: int, action: str | None, run_id: int | None, limit: int | None, event_status: str | None self, action: str | None, run_id: int | None, limit: int | None, event_status: str | None
) -> dict: ) -> dict:
params = {"action": action, "run_id": run_id, "event_status": event_status, "limit": limit} params = {"action": action, "run_id": run_id, "event_status": event_status, "limit": limit}
params = utils_base.filter_None_dict(to_filter=params) params = utils_base.filter_None_dict(to_filter=params)
async with self._ns_client.get(url=f"/runners/{runner_id}/events", params=params) as resp: async with self.get(url=f"/events", params=params) as resp:
return await resp.json() return await resp.json()
async def update_runner(self, updates: dict[str, typing.Any]) -> dict: async def update_runner(self, updates: dict[str, typing.Any]) -> dict:
...@@ -474,6 +485,27 @@ class RunnerClient: ...@@ -474,6 +485,27 @@ class RunnerClient:
async with self._ns_client.get(url=f"/runners") as resp: async with self._ns_client.get(url=f"/runners") as resp:
return await resp.json() return await resp.json()
async def send_heartbeat(self) -> None:
async with self.put(url="/heartbeat") as resp:
await resp.json()
async def filter_get_runs(
self,
run_id: int | None = None,
instantiation_id: int | None = None,
state: str | None = None,
limit: int | None = None,
):
obj = {
"id": run_id,
"instantiation_id": instantiation_id,
"state": state,
"limit": limit,
}
utils_base.filter_None_dict(to_filter=obj)
async with self.post(url="/filter_get_run", json=obj) as resp:
return await resp.json()
async def next_run(self) -> dict | None: async def next_run(self) -> dict | None:
async with self.get(f"/next_run") as resp: async with self.get(f"/next_run") as resp:
if resp.status == 200: if resp.status == 200:
...@@ -496,7 +528,7 @@ class RunnerClient: ...@@ -496,7 +528,7 @@ class RunnerClient:
"instantiation_id": 42, "instantiation_id": 42,
} }
async with self.put(url=f"/update_run/{run_id}", json=obj) as resp: async with self.put(url=f"/update_run/{run_id}", json=obj) as resp:
ret = await resp.json() await resp.json()
async def send_out( async def send_out(
self, self,
......
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