Skip to content

Commit

Permalink
Rename get_final_command() -> get_most_recently_finalized_command().
Browse files Browse the repository at this point in the history
The original name could be misread as "the final command in the run," which it is usually not.
  • Loading branch information
SyntaxColoring committed May 16, 2024
1 parent 555077b commit 4232945
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions api/src/opentrons/protocol_engine/state/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,13 +606,13 @@ def get_current(self) -> Optional[CurrentCommand]:
index=running_command.index,
)

final_command = self.get_final_command()
if final_command:
most_recently_finalized_command = self.get_most_recently_finalized_command()
if most_recently_finalized_command:
return CurrentCommand(
command_id=final_command.command.id,
command_key=final_command.command.key,
created_at=final_command.command.createdAt,
index=final_command.index,
command_id=most_recently_finalized_command.command.id,
command_key=most_recently_finalized_command.command.key,
created_at=most_recently_finalized_command.command.createdAt,
index=most_recently_finalized_command.index,
)

return None
Expand Down Expand Up @@ -676,7 +676,7 @@ def get_is_running(self) -> bool:
"""Get whether the protocol is running & queued commands should be executed."""
return self._state.queue_status == QueueStatus.RUNNING

def get_final_command(self) -> Optional[CommandEntry]:
def get_most_recently_finalized_command(self) -> Optional[CommandEntry]:
"""Get the most recent command that has reached its final `status`. See get_command_is_final."""
run_requested_to_stop = self._state.run_result is not None

Expand All @@ -689,22 +689,22 @@ def get_final_command(self) -> Optional[CommandEntry]:
else:
return self._state.command_history.get_prev(tail_command.command.id)
else:
final_command = self._state.command_history.get_terminal_command()
most_recently_finalized = self._state.command_history.get_terminal_command()
# This iteration is effectively O(1) as we'll only ever have to iterate one or two times at most.
while final_command is not None:
while most_recently_finalized is not None:
next_command = self._state.command_history.get_next(
final_command.command.id
most_recently_finalized.command.id
)
if (
next_command is not None
and next_command.command.status != CommandStatus.QUEUED
and next_command.command.status != CommandStatus.RUNNING
):
final_command = next_command
most_recently_finalized = next_command
else:
break

return final_command
return most_recently_finalized

def get_command_is_final(self, command_id: str) -> bool:
"""Get whether a given command has reached its final `status`.
Expand Down

0 comments on commit 4232945

Please sign in to comment.