Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(robot-server): Robot server command responses #7170

Merged
merged 6 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ async def execute(self, command: Command) \
:raises: SessionCommandException
"""
raise UnsupportedCommandException(
f"'{command.content.name}' is not supported"
f"'{command.request.command}' is not supported"
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ def __init__(self, command_handler: CommandHandler):
async def execute(self, command: Command) -> CompletedCommand:
"""Execute command"""
with duration() as time_it:
name_arg = command.content.name
data = command.content.data
name_arg = command.request.command
data = command.request.data
data_arg = data.dict() if data else {}

await self._callable(name_arg, data_arg)

return CompletedCommand(
content=command.content,
request=command.request,
meta=command.meta,
result=CommandResult(started_at=time_it.start,
completed_at=time_it.end)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,46 @@
from datetime import datetime
from dataclasses import dataclass, field
from typing import Optional
from typing import Optional, Generic, TypeVar

from robot_server.service.session.models.command import (
CommandDataType, CommandStatus, CommandResultType)
from robot_server.service.session.models.command_definitions import \
CommandDefinitionType
CommandStatus, RequestTypes)
from robot_server.service.session.models.common import (
IdentifierType, create_identifier)
from opentrons.util.helpers import utc_now


@dataclass(frozen=True)
class CommandContent:
name: CommandDefinitionType
data: CommandDataType


@dataclass(frozen=True)
class CommandMeta:
identifier: IdentifierType = field(default_factory=create_identifier)
created_at: datetime = field(default_factory=utc_now)


ResultTypeT = TypeVar("ResultTypeT")


@dataclass(frozen=True)
class CommandResult:
class CommandResult(Generic[ResultTypeT]):
started_at: datetime
completed_at: datetime
status: CommandStatus = CommandStatus.executed
data: Optional[CommandResultType] = None
data: Optional[ResultTypeT] = None


@dataclass(frozen=True)
class Command:
content: CommandContent
request: RequestTypes
meta: CommandMeta = field(default_factory=CommandMeta)


@dataclass(frozen=True)
class CompletedCommand:
content: CommandContent
request: RequestTypes
meta: CommandMeta
result: CommandResult


def create_command(name: CommandDefinitionType,
data: CommandDataType) -> Command:
def create_command(request: RequestTypes) -> Command:
"""Create a command object"""
return Command(
content=CommandContent(
name=name,
data=data
)
request=request
)

This file was deleted.

Loading