diff --git a/.github/workflows/ci.yml b/.github/workflows/test-api-server.yml similarity index 95% rename from .github/workflows/ci.yml rename to .github/workflows/test-api-server.yml index c879d0cf..87338a92 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/test-api-server.yml @@ -3,8 +3,12 @@ name: Python API Server Tests on: push: branches: [main] + paths: + - 'api-server/**' pull_request: branches: [main] + paths: + - 'api-server/**' jobs: test: diff --git a/python-sdk/exospherehost/node/BaseNode.py b/python-sdk/exospherehost/node/BaseNode.py index 633f2833..3d6129d5 100644 --- a/python-sdk/exospherehost/node/BaseNode.py +++ b/python-sdk/exospherehost/node/BaseNode.py @@ -1,5 +1,5 @@ from abc import ABC, abstractmethod -from typing import Optional, Any +from typing import Optional, Any, List class BaseNode(ABC): @@ -8,7 +8,7 @@ def __init__(self, unique_name: Optional[str] = None): self.unique_name: Optional[str] = unique_name @abstractmethod - async def execute(self, inputs: dict[str, Any]) -> dict[str, Any]: + async def execute(self, inputs: dict[str, Any]) -> dict[str, Any] | List[dict[str, Any]]: pass def get_unique_name(self) -> str: diff --git a/python-sdk/exospherehost/runtime.py b/python-sdk/exospherehost/runtime.py index 575a7bea..ec014a2a 100644 --- a/python-sdk/exospherehost/runtime.py +++ b/python-sdk/exospherehost/runtime.py @@ -69,7 +69,7 @@ async def _enqueue(self): await sleep(self._poll_interval) - async def _notify_executed(self, state_id: str, outputs: dict[str, Any]): + async def _notify_executed(self, state_id: str, outputs: List[dict[str, Any]]): async with ClientSession() as session: endpoint = self._get_executed_endpoint(state_id) body = {"outputs": outputs} @@ -112,7 +112,15 @@ async def _worker(self): try: node = self._node_mapping[state["node_name"]] outputs = await node.execute(state["inputs"]) # type: ignore + + if outputs is None: + outputs = [] + + if isinstance(outputs, dict): + outputs = [outputs] + await self._notify_executed(state["state_id"], outputs) + except Exception as e: await self._notify_errored(state["state_id"], str(e)) diff --git a/state-manager/app/models/executed_models.py b/state-manager/app/models/executed_models.py index 11441a04..dc0935d4 100644 --- a/state-manager/app/models/executed_models.py +++ b/state-manager/app/models/executed_models.py @@ -1,9 +1,9 @@ from pydantic import BaseModel, Field -from typing import Any +from typing import Any, List from .state_status_enum import StateStatusEnum class ExecutedRequestModel(BaseModel): - outputs: dict[str, Any] = Field(..., description="Outputs of the state") + outputs: List[dict[str, Any]] = Field(..., description="Outputs of the state") class ExecutedResponseModel(BaseModel):