-
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.
fix(api-client, react-api-client, app, robot-server): support multipl…
…e recovery policies during a run (#16950) Closes RQA-3670 We need to support the client ignoring several different classes of errors in a single run, which means the app needs to know the current recovery policy and be able to modify. This PR adds the necessary infrastructure to support that. Co-authored-by: Max Marrone <[email protected]>
- Loading branch information
1 parent
64aaeb9
commit 7e6c8ee
Showing
18 changed files
with
396 additions
and
127 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { GET, request } from '../request' | ||
|
||
import type { HostConfig } from '../types' | ||
import type { ResponsePromise } from '../request' | ||
import type { ErrorRecoveryPolicyResponse } from './types' | ||
|
||
export function getErrorRecoveryPolicy( | ||
config: HostConfig, | ||
runId: string | ||
): ResponsePromise<ErrorRecoveryPolicyResponse> { | ||
return request<ErrorRecoveryPolicyResponse>( | ||
GET, | ||
`/runs/${runId}/errorRecoveryPolicy`, | ||
null, | ||
config | ||
) | ||
} |
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
60 changes: 60 additions & 0 deletions
60
app/src/resources/runs/useUpdateRecoveryPolicyWithStrategy.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,60 @@ | ||
import { | ||
useHost, | ||
useUpdateErrorRecoveryPolicy, | ||
} from '@opentrons/react-api-client' | ||
import { getErrorRecoveryPolicy } from '@opentrons/api-client' | ||
|
||
import type { | ||
HostConfig, | ||
RecoveryPolicyRulesParams, | ||
UpdateErrorRecoveryPolicyResponse, | ||
} from '@opentrons/api-client' | ||
|
||
/** | ||
* append - Add a new policy rule to the end of the existing recovery policy. | ||
*/ | ||
export type UpdatePolicyStrategy = 'append' | ||
|
||
export interface UpdateErrorRecoveryPolicyWithStrategy { | ||
runId: string | ||
newPolicy: RecoveryPolicyRulesParams[number] | ||
strategy: UpdatePolicyStrategy | ||
} | ||
|
||
export function useUpdateRecoveryPolicyWithStrategy( | ||
runId: string | ||
): ( | ||
newPolicy: UpdateErrorRecoveryPolicyWithStrategy['newPolicy'], | ||
strategy: UpdateErrorRecoveryPolicyWithStrategy['strategy'] | ||
) => Promise<UpdateErrorRecoveryPolicyResponse> { | ||
const host = useHost() | ||
|
||
const { | ||
mutateAsync: updateErrorRecoveryPolicy, | ||
} = useUpdateErrorRecoveryPolicy(runId) | ||
|
||
return ( | ||
newPolicy: UpdateErrorRecoveryPolicyWithStrategy['newPolicy'], | ||
strategy: UpdateErrorRecoveryPolicyWithStrategy['strategy'] | ||
) => | ||
getErrorRecoveryPolicy(host as HostConfig, runId).then(res => { | ||
const existingPolicyRules = res.data.data.policyRules.map(rule => ({ | ||
commandType: rule.matchCriteria.command.commandType, | ||
errorType: rule.matchCriteria.command.error.errorType, | ||
ifMatch: rule.ifMatch, | ||
})) | ||
|
||
const buildUpdatedPolicy = (): RecoveryPolicyRulesParams => { | ||
switch (strategy) { | ||
case 'append': | ||
return [...existingPolicyRules, newPolicy] | ||
default: { | ||
console.error('Unhandled policy strategy, defaulting to append.') | ||
return [...existingPolicyRules, newPolicy] | ||
} | ||
} | ||
} | ||
|
||
return updateErrorRecoveryPolicy(buildUpdatedPolicy()) | ||
}) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useQuery } from 'react-query' | ||
|
||
import { getErrorRecoveryPolicy } from '@opentrons/api-client' | ||
|
||
import { useHost } from '../api' | ||
|
||
import type { UseQueryOptions, UseQueryResult } from 'react-query' | ||
import type { | ||
ErrorRecoveryPolicyResponse, | ||
HostConfig, | ||
} from '@opentrons/api-client' | ||
|
||
export function useErrorRecoveryPolicy( | ||
runId: string, | ||
options: UseQueryOptions<ErrorRecoveryPolicyResponse, Error> = {} | ||
): UseQueryResult<ErrorRecoveryPolicyResponse, Error> { | ||
const host = useHost() | ||
|
||
const query = useQuery<ErrorRecoveryPolicyResponse, Error>( | ||
[host, 'runs', runId, 'errorRecoveryPolicy'], | ||
() => | ||
getErrorRecoveryPolicy(host as HostConfig, runId) | ||
.then(response => response.data) | ||
.catch(e => { | ||
throw e | ||
}), | ||
options | ||
) | ||
|
||
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
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.