-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(robot-server, app): add a new endpoint for fast-fetching all run…
… commands (#15031) # Overview **Robot server changes:** Adds a new endpoint- `GET /runs/:run_id/commandsAsPreSerializedList` to the run commands router. This endpoint returns a list of pre-serialized commands (that are valid json objects) of a finished run. This endpoint is a much faster alternative to the `GET /runs/:run_id/commands` endpoint when fetching all commands of a completed run. Also adds notification publishing when pre-serialized commands become available for a run. **App changes** closes RQA-2645 and RQA-2647 # Risk assessment Back-end: New endpoint so impact on existing code is close to none. App: Medium. Fixes issues in existing behavior of handling historical runs. --------- Co-authored-by: ncdiehl11 <[email protected]> Co-authored-by: ncdiehl11 <[email protected]>
- Loading branch information
1 parent
78ac8fc
commit f44872b
Showing
25 changed files
with
432 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
api-client/src/runs/commands/getCommandsAsPreSerializedList.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { GET, request } from '../../request' | ||
|
||
import type { ResponsePromise } from '../../request' | ||
import type { HostConfig } from '../../types' | ||
import type { | ||
CommandsAsPreSerializedListData, | ||
GetCommandsParams, | ||
} from './types' | ||
|
||
export function getCommandsAsPreSerializedList( | ||
config: HostConfig, | ||
runId: string, | ||
params: GetCommandsParams | ||
): ResponsePromise<CommandsAsPreSerializedListData> { | ||
return request<CommandsAsPreSerializedListData>( | ||
GET, | ||
`/runs/${runId}/commandsAsPreSerializedList`, | ||
null, | ||
config, | ||
params | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
app/src/resources/runs/useNotifyAllCommandsAsPreSerializedList.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as React from 'react' | ||
|
||
import { useAllCommandsAsPreSerializedList } from '@opentrons/react-api-client' | ||
|
||
import { useNotifyService } from '../useNotifyService' | ||
|
||
import type { UseQueryResult } from 'react-query' | ||
import type { AxiosError } from 'axios' | ||
import type { CommandsData, GetCommandsParams } from '@opentrons/api-client' | ||
import type { | ||
QueryOptionsWithPolling, | ||
HTTPRefetchFrequency, | ||
} from '../useNotifyService' | ||
|
||
export function useNotifyAllCommandsAsPreSerializedList( | ||
runId: string | null, | ||
params?: GetCommandsParams | null, | ||
options: QueryOptionsWithPolling<CommandsData, AxiosError> = {} | ||
): UseQueryResult<CommandsData, AxiosError> { | ||
const [refetch, setRefetch] = React.useState<HTTPRefetchFrequency>(null) | ||
|
||
useNotifyService<CommandsData, AxiosError>({ | ||
topic: `robot-server/runs/pre_serialized_commands/${runId}`, | ||
setRefetch, | ||
options, | ||
}) | ||
|
||
const httpResponse = useAllCommandsAsPreSerializedList(runId, params, { | ||
...options, | ||
enabled: options?.enabled !== false && refetch != null, | ||
onSettled: refetch === 'once' ? () => setRefetch(null) : () => null, | ||
}) | ||
|
||
return httpResponse | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
react-api-client/src/runs/useAllCommandsAsPreSerializedList.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { UseQueryResult, useQuery } from 'react-query' | ||
import { getCommandsAsPreSerializedList } from '@opentrons/api-client' | ||
import { useHost } from '../api' | ||
import type { UseQueryOptions } from 'react-query' | ||
import type { | ||
GetCommandsParams, | ||
HostConfig, | ||
CommandsData, | ||
RunCommandSummary, | ||
} from '@opentrons/api-client' | ||
|
||
const DEFAULT_PAGE_LENGTH = 30 | ||
export const DEFAULT_PARAMS: GetCommandsParams = { | ||
cursor: null, | ||
pageLength: DEFAULT_PAGE_LENGTH, | ||
} | ||
|
||
export function useAllCommandsAsPreSerializedList<TError = Error>( | ||
runId: string | null, | ||
params?: GetCommandsParams | null, | ||
options: UseQueryOptions<CommandsData, TError> = {} | ||
): UseQueryResult<CommandsData, TError> { | ||
const host = useHost() | ||
const nullCheckedParams = params ?? DEFAULT_PARAMS | ||
|
||
const allOptions: UseQueryOptions<CommandsData, TError> = { | ||
...options, | ||
enabled: host !== null && runId != null && options.enabled !== false, | ||
} | ||
const { cursor, pageLength } = nullCheckedParams | ||
const query = useQuery<CommandsData, TError>( | ||
[host, 'runs', runId, 'getCommandsAsPreSerializedList', cursor, pageLength], | ||
() => { | ||
return getCommandsAsPreSerializedList( | ||
host as HostConfig, | ||
runId as string, | ||
nullCheckedParams | ||
).then(response => { | ||
const responseData = response.data | ||
return { | ||
...responseData, | ||
data: responseData.data.map( | ||
command => JSON.parse(command) as RunCommandSummary | ||
), | ||
} | ||
}) | ||
}, | ||
allOptions | ||
) | ||
|
||
return query | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.