Skip to content

Commit

Permalink
feat(robot-server): Add failedCommandId to command summary model (#15467
Browse files Browse the repository at this point in the history
)
  • Loading branch information
SyntaxColoring committed Jun 20, 2024
1 parent c459fa3 commit 93231a2
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
from typing import List, Optional

from opentrons.protocol_engine import (
CommandStatus,
CommandIntent,
CommandType,
CommandParams,
EngineStatus as RunStatus,
ErrorOccurrence,
LoadedPipette,
Expand All @@ -20,42 +16,6 @@
from robot_server.service.json_api import ResourceModel


# TODO(mc, 2022-02-01): since the `/maintenance_runs/:run_id/commands` response is now paginated,
# this summary model is a lot less useful. Remove and replace with full `Command`
# models once problematically large objects like full labware and module definitions
# are no longer part of the public command.result API
class MaintenanceRunCommandSummary(ResourceModel):
"""A stripped down model of a full Command for usage in a Maintenance run response."""

id: str = Field(..., description="Unique command identifier.")
key: str = Field(
...,
description="An identifier representing this command as a step in a protocol.",
)
commandType: CommandType = Field(..., description="Specific type of command.")
createdAt: datetime = Field(..., description="Command creation timestamp")
startedAt: Optional[datetime] = Field(
None,
description="Command execution start timestamp, if started",
)
completedAt: Optional[datetime] = Field(
None,
description="Command execution completed timestamp, if completed",
)
status: CommandStatus = Field(..., description="Execution status of the command.")
error: Optional[ErrorOccurrence] = Field(
None,
description="Error occurrence, if status is 'failed'",
)
# TODO(mc, 2022-02-01): this does not allow the command summary object to
# be narrowed based on `commandType`. Will be resolved by TODO above
params: CommandParams = Field(..., description="Command execution parameters.")
intent: Optional[CommandIntent] = Field(
None,
description="Why this command was added to the run.",
)


class MaintenanceRun(ResourceModel):
"""Maintenance run resource model."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@
CommandLink,
CommandLinkMeta,
)
from robot_server.runs.run_models import RunCommandSummary

from ..maintenance_run_models import (
MaintenanceRunCommandSummary,
MaintenanceRunNotFoundError,
)
from ..maintenance_run_models import MaintenanceRunNotFoundError
from ..maintenance_run_data_manager import MaintenanceRunDataManager
from ..maintenance_engine_store import MaintenanceEngineStore
from ..dependencies import (
Expand Down Expand Up @@ -177,7 +175,7 @@ async def create_run_command(
),
responses={
status.HTTP_200_OK: {
"model": MultiBody[MaintenanceRunCommandSummary, CommandCollectionLinks]
"model": MultiBody[RunCommandSummary, CommandCollectionLinks]
},
status.HTTP_404_NOT_FOUND: {"model": ErrorBody[RunNotFound]},
},
Expand All @@ -199,7 +197,7 @@ async def get_run_commands(
run_data_manager: MaintenanceRunDataManager = Depends(
get_maintenance_run_data_manager
),
) -> PydanticResponse[MultiBody[MaintenanceRunCommandSummary, CommandCollectionLinks]]:
) -> PydanticResponse[MultiBody[RunCommandSummary, CommandCollectionLinks]]:
"""Get a summary of a set of commands in a run.
Arguments:
Expand All @@ -221,7 +219,7 @@ async def get_run_commands(
recovery_target_command = run_data_manager.get_recovery_target_command(run_id=runId)

data = [
MaintenanceRunCommandSummary.construct(
RunCommandSummary.construct(
id=c.id,
key=c.key,
commandType=c.commandType,
Expand All @@ -232,6 +230,7 @@ async def get_run_commands(
completedAt=c.completedAt,
params=c.params,
error=c.error,
failedCommandId=c.failedCommandId,
)
for c in command_slice.commands
]
Expand Down
1 change: 1 addition & 0 deletions robot-server/robot_server/runs/router/commands_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ async def get_run_commands(
params=c.params,
error=c.error,
notes=c.notes,
failedCommandId=c.failedCommandId,
)
for c in command_slice.commands
]
Expand Down
6 changes: 6 additions & 0 deletions robot-server/robot_server/runs/run_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ class RunCommandSummary(ResourceModel):
None,
description="Notes pertaining to this command.",
)
failedCommandId: Optional[str] = Field(
None,
description=(
"FIXIT command use only. Reference of the failed command id we are trying to fix."
),
)


class Run(ResourceModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
MaintenanceRunDataManager,
)
from robot_server.maintenance_runs.maintenance_run_models import (
MaintenanceRunCommandSummary,
MaintenanceRunNotFoundError,
)
from robot_server.maintenance_runs.router.commands_router import (
Expand All @@ -37,6 +36,7 @@
CommandLink,
CommandLinkMeta,
)
from robot_server.runs.run_models import RunCommandSummary


async def test_get_current_run_from_url(
Expand Down Expand Up @@ -175,6 +175,7 @@ async def test_get_run_commands(
createdAt=datetime(year=2024, month=4, day=4),
detail="Things are not looking good.",
),
failedCommandId="failed-command-id",
)

decoy.when(
Expand Down Expand Up @@ -214,7 +215,7 @@ async def test_get_run_commands(
)

assert result.content.data == [
MaintenanceRunCommandSummary(
RunCommandSummary(
id="command-id",
key="command-key",
commandType="waitForResume",
Expand All @@ -230,6 +231,7 @@ async def test_get_run_commands(
createdAt=datetime(year=2024, month=4, day=4),
detail="Things are not looking good.",
),
failedCommandId="failed-command-id",
)
]
assert result.content.meta == MultiBodyMeta(cursor=1, totalLength=3)
Expand Down
2 changes: 2 additions & 0 deletions robot-server/tests/runs/router/test_commands_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ async def test_get_run_commands(
detail="Things are not looking good.",
),
notes=[long_note, unenumed_note],
failedCommandId="failed-command-id",
)

decoy.when(mock_run_data_manager.get_current_command("run-id")).then_return(
Expand Down Expand Up @@ -360,6 +361,7 @@ async def test_get_run_commands(
detail="Things are not looking good.",
),
notes=[long_note, unenumed_note],
failedCommandId="failed-command-id",
)
]
assert result.content.meta == MultiBodyMeta(cursor=1, totalLength=3)
Expand Down

0 comments on commit 93231a2

Please sign in to comment.