Skip to content

Commit

Permalink
get default orchestrator WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarZanzouri committed May 31, 2024
1 parent bcdfcea commit a079763
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
8 changes: 6 additions & 2 deletions api/src/opentrons/protocol_runner/run_orchestrator.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
10 changes: 5 additions & 5 deletions robot-server/robot_server/commands/get_default_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
12 changes: 7 additions & 5 deletions robot-server/robot_server/runs/engine_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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."
Expand Down

0 comments on commit a079763

Please sign in to comment.