From d75461b3317f2d750df9bc8ed75649af0fe90fe7 Mon Sep 17 00:00:00 2001 From: tamarzanzouri Date: Thu, 25 Apr 2024 17:11:12 -0400 Subject: [PATCH] WIP starting to move setting the queue to the runner --- .../protocol_engine/state/command_history.py | 38 +++++++++---------- .../protocol_runner/protocol_runner.py | 21 +++++++++- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/api/src/opentrons/protocol_engine/state/command_history.py b/api/src/opentrons/protocol_engine/state/command_history.py index b21fca030ae..73d9a8fcc61 100644 --- a/api/src/opentrons/protocol_engine/state/command_history.py +++ b/api/src/opentrons/protocol_engine/state/command_history.py @@ -21,20 +21,20 @@ class CommandEntry: class CommandHistory: """Command state container for command data.""" - _all_command_ids: List[str] - """All command IDs, in insertion order.""" - - _commands_by_id: Dict[str, CommandEntry] - """All command resources, in insertion order, mapped by their unique IDs.""" - - _queued_command_ids: OrderedSet[str] - """The IDs of queued commands, in FIFO order""" - - _queued_setup_command_ids: OrderedSet[str] - """The IDs of queued setup commands, in FIFO order""" - - _queued_fixit_command_ids: OrderedSet[str] - """The IDs of queued fixit commands, in FIFO order""" + # _all_command_ids: List[str] + # """All command IDs, in insertion order.""" + # + # _commands_by_id: Dict[str, CommandEntry] + # """All command resources, in insertion order, mapped by their unique IDs.""" + # + # _queued_command_ids: OrderedSet[str] + # """The IDs of queued commands, in FIFO order""" + # + # _queued_setup_command_ids: OrderedSet[str] + # """The IDs of queued setup commands, in FIFO order""" + # + # _queued_fixit_command_ids: OrderedSet[str] + # """The IDs of queued fixit commands, in FIFO order""" _running_command_id: Optional[str] """The ID of the currently running command, if any""" @@ -43,11 +43,11 @@ class CommandHistory: """ID of the most recent command that SUCCEEDED or FAILED, if any""" def __init__(self) -> None: - self._all_command_ids = [] - self._queued_command_ids = OrderedSet() - self._queued_setup_command_ids = OrderedSet() - self._queued_fixit_command_ids = OrderedSet() - self._commands_by_id = OrderedDict() + # self._all_command_ids = [] + # self._queued_command_ids = OrderedSet() + # self._queued_setup_command_ids = OrderedSet() + # self._queued_fixit_command_ids = OrderedSet() + # self._commands_by_id = OrderedDict() self._running_command_id = None self._terminal_command_id = None diff --git a/api/src/opentrons/protocol_runner/protocol_runner.py b/api/src/opentrons/protocol_runner/protocol_runner.py index 857a785fcb5..6bcfcd50c27 100644 --- a/api/src/opentrons/protocol_runner/protocol_runner.py +++ b/api/src/opentrons/protocol_runner/protocol_runner.py @@ -21,7 +21,7 @@ ProtocolEngine, StateSummary, Command, - commands as pe_commands, + commands as pe_commands, CommandIntent, ) from opentrons.protocols.parse import PythonParseMode from opentrons.util.broker import Broker @@ -158,6 +158,25 @@ async def run( ) -> RunResult: """Run a given protocol to completion.""" + def set_command_queued(self, command: Command) -> None: + """Validate and mark a command as queued in the command history.""" + assert command.status == CommandStatus.QUEUED + assert not self.has(command.id) + + next_index = self.length() + updated_command = CommandEntry( + index=next_index, + command=command, + ) + self._add(command.id, updated_command) + + if command.intent == CommandIntent.SETUP: + self._add_to_setup_queue(command.id) + elif command.intent == CommandIntent.FIXIT: + self._add_to_fixit_queue(command.id) + else: + self._add_to_queue(command.id) + class PythonAndLegacyRunner(AbstractRunner): """Protocol runner implementation for Python protocols, and JSON protocols ≤v5."""