Skip to content

Commit

Permalink
feat(orchestrator): add ability to re-trigger workflow in error state (
Browse files Browse the repository at this point in the history
…#1624)

* Add ability to retrigger workflow in error state

* fix unnecessary assertion issue
  • Loading branch information
yzhao583 authored May 9, 2024
1 parent d30c141 commit 8709a37
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 14 deletions.
1 change: 1 addition & 0 deletions plugins/orchestrator-common/src/QueryParams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const QUERY_PARAM_BUSINESS_KEY = 'businessKey' as const;
export const QUERY_PARAM_INSTANCE_ID = 'instanceId' as const;
export const QUERY_PARAM_INSTANCE_STATE = 'state';
export const QUERY_PARAM_INCLUDE_ASSESSMENT = 'includeAssessment' as const;
export const QUERY_PARAM_ASSESSMENT_INSTANCE_ID =
'assessmentInstanceId' as const;
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Grid } from '@material-ui/core';
import {
QUERY_PARAM_ASSESSMENT_INSTANCE_ID,
QUERY_PARAM_INSTANCE_ID,
QUERY_PARAM_INSTANCE_STATE,
WorkflowInputSchemaResponse,
} from '@janus-idp/backstage-plugin-orchestrator-common';

Expand All @@ -42,6 +43,9 @@ export const ExecuteWorkflowPage = () => {
const [assessmentInstanceId] = useQueryParamState<string>(
QUERY_PARAM_ASSESSMENT_INSTANCE_ID,
);
const [instanceState] = useQueryParamState<string>(
QUERY_PARAM_INSTANCE_STATE,
);
const navigate = useNavigate();
const instanceLink = useRouteRef(workflowInstanceRouteRef);
const {
Expand Down Expand Up @@ -85,6 +89,39 @@ export const ExecuteWorkflowPage = () => {
[orchestratorApi, workflowId, navigate, instanceLink, assessmentInstanceId],
);

const isErrorState = React.useMemo(
() => instanceState === 'ERROR',
[instanceState],
);

const handleRetrigger = useCallback(
async (getParameters: () => JsonObject) => {
setUpdateError(undefined);
let parameters: JsonObject = {};
try {
parameters = getParameters();
} catch (err) {
setUpdateError(getErrorObject(err));
return;
}
if (instanceId) {
try {
setIsExecuting(true);
const response = await orchestratorApi.retriggerInstanceInError({
instanceId,
inputData: parameters,
});
navigate(instanceLink({ instanceId: response.id }));
} catch (err) {
setUpdateError(getErrorObject(err));
} finally {
setIsExecuting(false);
}
}
},
[orchestratorApi, instanceId, navigate, instanceLink],
);

const onReset = useCallback(() => {
setUpdateError(undefined);
}, [setUpdateError]);
Expand Down Expand Up @@ -128,13 +165,13 @@ export const ExecuteWorkflowPage = () => {
<StepperForm
steps={schemaResponse.schemaSteps}
isComposedSchema={schemaResponse.isComposedSchema}
handleExecute={handleExecute}
handleExecute={isErrorState ? handleRetrigger : handleExecute}
isExecuting={isExecuting}
onReset={onReset}
/>
) : (
<JsonTextAreaForm
handleExecute={handleExecute}
handleExecute={isErrorState ? handleRetrigger : handleExecute}
isExecuting={isExecuting}
/>
)}
Expand Down
38 changes: 26 additions & 12 deletions plugins/orchestrator/src/components/WorkflowInstancePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
AssessedProcessInstance,
QUERY_PARAM_ASSESSMENT_INSTANCE_ID,
QUERY_PARAM_INSTANCE_ID,
QUERY_PARAM_INSTANCE_STATE,
} from '@janus-idp/backstage-plugin-orchestrator-common';

import { orchestratorApiRef } from '../api';
Expand Down Expand Up @@ -154,6 +155,7 @@ export const WorkflowInstancePage = ({
const urlToNavigate = buildUrl(routeUrl, {
[QUERY_PARAM_INSTANCE_ID]: value.instance.id,
[QUERY_PARAM_ASSESSMENT_INSTANCE_ID]: value.assessedBy?.id,
[QUERY_PARAM_INSTANCE_STATE]: value.instance.state,
});
navigate(urlToNavigate);
}, [value, navigate, executeWorkflowLink]);
Expand Down Expand Up @@ -196,18 +198,30 @@ export const WorkflowInstancePage = ({
/>
<Grid container item justifyContent="flex-end" spacing={1}>
{!canRerun && (
<Grid item>
<Button
variant="contained"
color="secondary"
disabled={!canAbort}
onClick={
canAbort ? toggleAbortConfirmationDialog : undefined
}
>
Abort
</Button>
</Grid>
<>
<Grid item>
<Button
variant="contained"
color="primary"
disabled={!canAbort}
onClick={canAbort ? handleRerun : undefined}
>
Retrigger
</Button>
</Grid>
<Grid item>
<Button
variant="contained"
color="secondary"
disabled={!canAbort}
onClick={
canAbort ? toggleAbortConfirmationDialog : undefined
}
>
Abort
</Button>
</Grid>
</>
)}
{!canAbort && (
<Grid item>
Expand Down

0 comments on commit 8709a37

Please sign in to comment.