Skip to content

Commit

Permalink
WIP starting to move setting the queue to the runner
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarZanzouri committed Apr 25, 2024
1 parent 347c193 commit d75461b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
38 changes: 19 additions & 19 deletions api/src/opentrons/protocol_engine/state/command_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -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

Expand Down
21 changes: 20 additions & 1 deletion api/src/opentrons/protocol_runner/protocol_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit d75461b

Please sign in to comment.