-
Notifications
You must be signed in to change notification settings - Fork 175
/
run_models.py
268 lines (243 loc) · 9.05 KB
/
run_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
"""Request and response models for run resources."""
from datetime import datetime
from pydantic import BaseModel, Field
from typing import List, Optional, Literal
from opentrons.protocol_engine import (
CommandStatus,
CommandIntent,
CommandType,
CommandParams,
EngineStatus as RunStatus,
ErrorOccurrence,
LoadedPipette,
LoadedLabware,
LoadedModule,
LabwareOffset,
LabwareOffsetCreate,
Liquid,
CommandNote,
)
from opentrons.protocol_engine.types import RunTimeParameter, RunTimeParamValuesType
from opentrons_shared_data.errors import GeneralError
from robot_server.service.json_api import ResourceModel
from robot_server.errors.error_responses import ErrorDetails
from .action_models import RunAction
class RunDataError(ErrorDetails):
"""A model for an error loading a run."""
title: str = Field(
"Run Data Error",
description="A short, human readable name for this type of error",
)
id: Literal["RunDataError"] = "RunDataError"
# TODO(mc, 2022-02-01): since the `/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 RunCommandSummary(ResourceModel):
"""A stripped down model of a full Command for usage in a 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.",
)
notes: Optional[List[CommandNote]] = Field(
None,
description="Notes pertaining to this command.",
)
class Run(ResourceModel):
"""Run resource model."""
ok: Literal[True] = True
id: str = Field(..., description="Unique run identifier.")
createdAt: datetime = Field(..., description="When the run was created")
status: RunStatus = Field(..., description="Execution status of the run")
current: bool = Field(
...,
description=(
"Whether this run is currently controlling the robot."
" There can be, at most, one current run."
),
)
actions: List[RunAction] = Field(
...,
description="Client-initiated run control actions, ordered oldest to newest.",
)
errors: List[ErrorOccurrence] = Field(
...,
description=(
"The run's fatal error, if there was one."
" For historical reasons, this is an array,"
" but it won't have more than one element."
),
)
pipettes: List[LoadedPipette] = Field(
...,
description="Pipettes that have been loaded into the run.",
)
modules: List[LoadedModule] = Field(
...,
description="Modules that have been loaded into the run.",
)
labware: List[LoadedLabware] = Field(
...,
description="Labware that has been loaded into the run.",
)
liquids: List[Liquid] = Field(
...,
description="Liquids loaded to the run.",
)
labwareOffsets: List[LabwareOffset] = Field(
...,
description="Labware offsets to apply as labware are loaded.",
)
runTimeParameters: List[RunTimeParameter] = Field(
default_factory=list,
description=(
"Run time parameters used during the run."
" These are the parameters that are defined in the protocol, with values"
" specified either in the run creation request or default values from the protocol"
" if none are specified in the request."
),
)
protocolId: Optional[str] = Field(
None,
description=(
"Protocol resource being run, if any. If not present, the run may"
" still be used to execute protocol commands over HTTP."
),
)
completedAt: Optional[datetime] = Field(
None,
description="Run completed at timestamp.",
)
startedAt: Optional[datetime] = Field(
None,
description="Run started at timestamp.",
)
class BadRun(ResourceModel):
"""Resource model representation for a bad run that could not be loaded."""
ok: Literal[False] = False
dataError: RunDataError = Field(..., description="Error from loading the data.")
id: str = Field(..., description="Unique run identifier.")
createdAt: datetime = Field(..., description="When the run was created")
status: RunStatus = Field(..., description="Execution status of the run")
current: bool = Field(
...,
description=(
"Whether this run is currently controlling the robot."
" There can be, at most, one current run."
),
)
actions: List[RunAction] = Field(
...,
description="Client-initiated run control actions, ordered oldest to newest. If these could not be loaded for this bad run, this will be null.",
)
errors: List[ErrorOccurrence] = Field(
...,
description=(
"The run's fatal error, if there was one."
" For historical reasons, this is an array,"
" but it won't have more than one element."
),
)
pipettes: List[LoadedPipette] = Field(
...,
description="Pipettes that have been loaded into the run.",
)
modules: List[LoadedModule] = Field(
...,
description="Modules that have been loaded into the run.",
)
labware: List[LoadedLabware] = Field(
...,
description="Labware that has been loaded into the run.",
)
liquids: List[Liquid] = Field(
...,
description="Liquids loaded to the run.",
)
labwareOffsets: List[LabwareOffset] = Field(
...,
description="Labware offsets to apply as labware are loaded.",
)
runTimeParameters: List[RunTimeParameter] = Field(
default_factory=list,
description=(
"Run time parameters used during the run."
" These are the parameters that are defined in the protocol, with values"
" specified either in the run creation request or default values from the protocol"
" if none are specified in the request."
),
)
protocolId: Optional[str] = Field(
None,
description=(
"Protocol resource being run, if any. If not present, the run may"
" still be used to execute protocol commands over HTTP."
),
)
completedAt: Optional[datetime] = Field(
None,
description="Run completed at timestamp.",
)
startedAt: Optional[datetime] = Field(
None,
description="Run started at timestamp.",
)
class RunCreate(BaseModel):
"""Create request data for a new run."""
protocolId: Optional[str] = Field(
None,
description="Protocol resource ID that this run will be using, if applicable.",
)
labwareOffsets: List[LabwareOffsetCreate] = Field(
default_factory=list,
description="Labware offsets to apply as labware are loaded.",
)
runTimeParameterValues: Optional[RunTimeParamValuesType] = Field(
None,
description="Key-value pairs of run-time parameters defined in a protocol.",
)
class RunUpdate(BaseModel):
"""Update request data for an existing run."""
current: Optional[bool] = Field(
None,
description=(
"Whether this run is currently controlling the robot."
" Setting `current` to `false` will deactivate the run."
),
)
class LabwareDefinitionSummary(BaseModel):
"""Summary of data about a created labware definition."""
definitionUri: str = Field(
...,
description="The definition's unique resource identifier in the run.",
)
class RunNotFoundError(GeneralError):
"""Error raised when a given Run ID is not found in the store."""
def __init__(self, run_id: str) -> None:
"""Initialize the error message from the missing ID."""
super().__init__(
message=f"Run {run_id} was not found.", detail={"runId": run_id}
)