From a07976365c7f33b270d0b6fc49d872a7c4fe4e15 Mon Sep 17 00:00:00 2001 From: tamarzanzouri Date: Fri, 31 May 2024 12:34:16 -0400 Subject: [PATCH] get default orchestrator WIP --- .../opentrons/protocol_runner/run_orchestrator.py | 8 ++++++-- .../robot_server/commands/get_default_engine.py | 10 +++++----- robot-server/robot_server/runs/engine_store.py | 12 +++++++----- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/api/src/opentrons/protocol_runner/run_orchestrator.py b/api/src/opentrons/protocol_runner/run_orchestrator.py index c87193f9da9..c693172a924 100644 --- a/api/src/opentrons/protocol_runner/run_orchestrator.py +++ b/api/src/opentrons/protocol_runner/run_orchestrator.py @@ -1,13 +1,14 @@ """Engine/Runner provider.""" from __future__ import annotations -from typing import Optional, Union, List +from typing import Optional, Union, List, Dict from anyio import move_on_after from build.lib.opentrons_shared_data.labware.dev_types import LabwareUri from opentrons_shared_data.labware.labware_definition import LabwareDefinition -from . import protocol_runner, AnyRunner, RunResult +from . import protocol_runner, RunResult from ..hardware_control import HardwareControlAPI +from ..hardware_control.modules import AbstractModule as HardwareModuleAPI from ..protocol_engine import ProtocolEngine, CommandCreate, Command, StateSummary, CommandPointer, CommandSlice from ..protocol_engine.types import PostRunHardwareState, EngineStatus, LabwareOffsetCreate, LabwareOffset, \ DeckConfigurationType, RunTimeParameter @@ -215,3 +216,6 @@ async def add_command_and_wait_for_interval(self, command: CommandCreate, wait_u def estop(self) -> None: return self._protocol_engine.estop() + + def use_attached_modules(self, modules_by_id: Dict[str, HardwareModuleAPI]) -> None: + self._protocol_engine.use_attached_modules(modules_by_id=modules_by_id) diff --git a/robot-server/robot_server/commands/get_default_engine.py b/robot-server/robot_server/commands/get_default_engine.py index 385b6eaba78..a2318c74826 100644 --- a/robot-server/robot_server/commands/get_default_engine.py +++ b/robot-server/robot_server/commands/get_default_engine.py @@ -30,14 +30,14 @@ class RunActive(ErrorDetails): errorCode: str = ErrorCodes.ROBOT_IN_USE.value.code -async def get_default_engine( +async def get_default_orchestrator( engine_store: EngineStore = Depends(get_engine_store), hardware_api: HardwareControlAPI = Depends(get_hardware), module_identifier: ModuleIdentifier = Depends(ModuleIdentifier), ) -> ProtocolEngine: - """Get the default engine with attached modules loaded.""" + """Get the default run orchestrator with attached modules loaded.""" try: - engine = await engine_store.get_default_engine() + orchestrator = await engine_store.get_default_orchestrator() except EngineConflictError as e: raise RunActive.from_exc(e).as_error(status.HTTP_409_CONFLICT) from e @@ -47,6 +47,6 @@ async def get_default_engine( for mod in attached_modules } - await engine.use_attached_modules(attached_module_spec) + await orchestrator.use_attached_modules(attached_module_spec) - return engine + return orchestrator diff --git a/robot-server/robot_server/runs/engine_store.py b/robot-server/robot_server/runs/engine_store.py index 20528bc9c00..508d0359a14 100644 --- a/robot-server/robot_server/runs/engine_store.py +++ b/robot-server/robot_server/runs/engine_store.py @@ -149,8 +149,8 @@ def current_run_id(self) -> Optional[str]: # TODO(tz, 2024-5-14): remove this once its all redirected via orchestrator # TODO(mc, 2022-03-21): this resource locking is insufficient; # come up with something more sophisticated without race condition holes. - async def get_default_engine(self) -> ProtocolEngine: - """Get a "default" ProtocolEngine to use outside the context of a run. + async def get_default_orchestrator(self) -> ProtocolEngine: + """Get a "default" RunOrchestrator to use outside the context of a run. Raises: EngineConflictError: if a run-specific engine is active. @@ -175,8 +175,8 @@ async def get_default_engine(self) -> ProtocolEngine: self._default_run_orchestrator = RunOrchestrator.build_orchestrator( protocol_engine=engine, hardware_api=self._hardware_api ) - return self._default_run_orchestrator.engine - return default_orchestrator.engine + return self._default_run_orchestrator + return default_orchestrator async def create( self, @@ -242,7 +242,9 @@ async def create( # concurrency hazard. If two requests simultaneously call this method, # they will both "succeed" (with undefined results) instead of one # raising EngineConflictError. - if isinstance(self.run_orchestrator.runner, PythonAndLegacyRunner): + if isinstance( + self.run_orchestrator.get_protocol_runner(), PythonAndLegacyRunner + ): assert ( protocol is not None ), "A Python protocol should have a protocol source file."