diff --git a/api/src/opentrons/protocol_engine/state/command_structure.py b/api/src/opentrons/protocol_engine/state/command_structure.py index 3366b535e8d..c98fea9e3cd 100644 --- a/api/src/opentrons/protocol_engine/state/command_structure.py +++ b/api/src/opentrons/protocol_engine/state/command_structure.py @@ -83,6 +83,9 @@ def get_failed_command(self) -> Optional[CommandEntry]: def get_queued_command_ids(self) -> OrderedSet[str]: return self._queued_command_ids + def get_queued_setup_command_ids(self) -> OrderedSet[str]: + return self._queued_setup_command_ids + def add_queued(self, queued_command: Command) -> None: assert queued_command.status == CommandStatus.QUEUED assert not self.has(queued_command.id) diff --git a/api/src/opentrons/protocol_engine/state/commands.py b/api/src/opentrons/protocol_engine/state/commands.py index e455c2e9886..d348ba1b88e 100644 --- a/api/src/opentrons/protocol_engine/state/commands.py +++ b/api/src/opentrons/protocol_engine/state/commands.py @@ -165,7 +165,6 @@ def __init__( run_result=None, run_error=None, finish_error=None, - failed_command=None, run_completed_at=None, run_started_at=None, latest_command_hash=None, @@ -473,13 +472,15 @@ def get_next_to_execute(self) -> Optional[str]: raise RunStoppedError("Engine was stopped") # if there is a setup command queued, prioritize it - next_setup_cmd = self._state.queued_setup_command_ids.head(None) + next_setup_cmd = self._state.command_structure.get_queued_command_ids().head( + None + ) if self._state.queue_status != QueueStatus.PAUSED and next_setup_cmd: return next_setup_cmd # if the queue is running, return the next protocol command if self._state.queue_status == QueueStatus.RUNNING: - return self._state.queued_command_ids.head(None) + return self._state.command_structure.get_queued_command_ids().head(None) # otherwise we've got nothing to do return None @@ -490,8 +491,8 @@ def get_is_okay_to_clear(self) -> bool: return True elif ( self.get_status() == EngineStatus.IDLE - and self._state.running_command_id is None - and len(self._state.queued_setup_command_ids) == 0 + and self._state.command_structure.get_running_command() is None + and len(self._state.command_structure.get_queued_setup_command_ids()) == 0 ): return True else: @@ -539,15 +540,14 @@ def get_all_commands_final(self) -> bool: CommandExecutionFailedError: if any added command failed, and its `intent` wasn't `setup`. """ - no_command_running = self._state.running_command_id is None + no_command_running = self._state.command_structure.get_running_command() is None no_command_to_execute = ( self._state.run_result is not None - or len(self._state.queued_command_ids) == 0 + or len(self._state.command_structure.get_queued_command_ids()) == 0 ) if no_command_running and no_command_to_execute: - for command_id in self._state.all_command_ids: - command = self._state.commands_by_id[command_id].command + for command in self._state.command_structure.get_all(): if command.error and command.intent != CommandIntent.SETUP: # TODO(tz, 7-11-23): avoid raising an error and return the status instead raise ProtocolCommandFailedError(