Skip to content

Commit

Permalink
feat: support checks for restart and rollback
Browse files Browse the repository at this point in the history
Signed-off-by: xu.zhu <xu.zhu.work@outlook.com>
  • Loading branch information
xuzhu-591 committed Nov 29, 2023
1 parent 2aa4094 commit 3ccc661
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 42 deletions.
2 changes: 2 additions & 0 deletions src/const.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export enum ResourceType {
export enum PublishType {
BUILD_DEPLOY = 'builddeploy',
DEPLOY = 'deploy',
RESTART = 'restart',
ROLLBACK = 'rollback',
}

export enum MemberType {
Expand Down
17 changes: 12 additions & 5 deletions src/pages/instances/Pods/components/ButtonBar.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions src/pages/instances/Pods/components/ButtonBarV2.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 26 additions & 18 deletions src/pages/instances/pipelines/Detail/MergeBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,17 @@ const Status = (props: StatusProps) => {

interface ConfirmButtonProps extends Omit<ButtonProps, 'type'> {
pipelinerunID: number;
pipelinerunAction: string;
forceRun: boolean;
}

const ConfirmButton = (props: ConfirmButtonProps) => {
const { pipelinerunID, forceRun: forceRunFlag, disabled } = props;
const {
pipelinerunID, pipelinerunAction, forceRun: forceRunFlag, disabled,
} = props;
const intl = useIntl();
const history = useHistory();
const { successAlert } = useModel('alert');
const { initialState } = useModel('@@initialState');
const { fullPath } = initialState?.resource || {};

Expand All @@ -109,32 +113,35 @@ const ConfirmButton = (props: ConfirmButtonProps) => {
};
}, [forceRunFlag, intl, disabled]);

const { run } = useRequest(() => runPipelineRun(pipelinerunID), {
onSuccess: () => {
history.push(`${fullPath}`);
},
manual: true,
});
const doRun = useCallback(() => {
if (forceRunFlag) {
return forceRunPipelineRun(pipelinerunID);
}
return runPipelineRun(pipelinerunID);
}, [forceRunFlag, pipelinerunID]);

const { run: forceRun } = useRequest(() => forceRunPipelineRun(pipelinerunID), {
const { run, loading } = useRequest(() => doRun(), {
onSuccess: () => {
switch (pipelinerunAction) {
case 'restart':
successAlert(intl.formatMessage({ id: 'pages.message.cluster.restart.success' }));
break;
case 'rollback':
successAlert(intl.formatMessage({ id: 'pages.message.cluster.rollback.submitted' }));
break;
default:
break;
}
history.push(`${fullPath}`);
},
manual: true,
});

const onClick = useCallback(() => {
if (forceRunFlag) {
forceRun();
} else {
run();
}
}, [forceRunFlag, forceRun, run]);

return (
<Button
type="primary"
onClick={onClick}
loading={loading}
onClick={run}
style={{ backgroundColor: params.color, borderColor: params.color }}
{...props}
>
Expand Down Expand Up @@ -233,7 +240,7 @@ const CheckRunItem = (props: { checkrun: PIPELINES.CheckRun }) => {
};

const MergeBox = (props: { pipelinerun: PIPELINES.Pipeline, checkruns?: PIPELINES.CheckRun[] }) => {
const { pipelinerun: { status, id }, checkruns = [] } = props;
const { pipelinerun: { status, id, action }, checkruns = [] } = props;
const needButton = useMemo(() => status === 'ready' || status === 'pending', [status]);
return (
<Row>
Expand All @@ -249,6 +256,7 @@ const MergeBox = (props: { pipelinerun: PIPELINES.Pipeline, checkruns?: PIPELINE
<ConfirmButton
forceRun={status === 'pending' && rbac.Permissions.forceRunPipelineRun.allowed}
pipelinerunID={id}
pipelinerunAction={action}
disabled={status === 'pending' && !rbac.Permissions.forceRunPipelineRun.allowed}
/>
<CancelButton pipelinerunID={id} />
Expand Down
30 changes: 18 additions & 12 deletions src/pages/instances/pipelines/Detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { useParams } from 'umi';
import { useRequest } from '@@/plugin-request/request';
import copy from 'copy-to-clipboard';
import { useMemo, useState } from 'react';
import {
Button, Card, Modal,
} from 'antd';
import { Button, Card, Modal } from 'antd';
import { CopyOutlined, FullscreenOutlined, ExclamationCircleOutlined } from '@ant-design/icons';
import PageWithBreadcrumb from '@/components/PageWithBreadcrumb';
import type { Param } from '@/components/DetailCard';
Expand All @@ -29,7 +27,7 @@ import {
import Utils from '@/utils';
import { PublishType } from '@/const';
import FullscreenModal from '@/components/FullscreenModal';
import { rollback } from '@/services/clusters/clusters';
import { createPipelineRun } from '@/services/clusters/clusters';
import { GitRefType } from '@/services/code/code';
import ButtonWithoutPadding from '@/components/Widget/ButtonWithoutPadding';
import MergeBox from './MergeBox';
Expand All @@ -49,15 +47,21 @@ export default (props: any) => {
const { initialState } = useModel('@@initialState');
const { id, fullPath } = initialState!.resource;

const pollingInterval = 6000;
const pollingInterval = 3000;

const { data: pipeline } = useRequest(() => getPipeline(pipelineID), {
const { data: checkruns, cancel: cancelListCheckRuns } = useRequest(() => listCheckRuns(pipelineID), {
pollingInterval,
pollingWhenHidden: false,
});
const { data: checkruns } = useRequest(() => listCheckRuns(pipelineID), {
const { data: pipeline, cancel: cancelGetPipeline } = useRequest(() => getPipeline(pipelineID), {
pollingInterval,
pollingWhenHidden: false,
onSuccess: (data) => {
if (data?.status && data?.status !== 'pending') {
cancelListCheckRuns();
cancelGetPipeline();
}
},
});
const { data: diff } = useRequest(() => getPipelineDiffs(pipelineID));
const { data: buildLog } = useRequest(() => queryPipelineLog(pipelineID), {
Expand Down Expand Up @@ -160,11 +164,13 @@ export default (props: any) => {
setFullscreen(true);
};

const { run: runRollback, loading } = useRequest((prID: number) => rollback(id, { pipelinerunID: prID }), {
onSuccess: () => {
// jump to pods' url
successAlert(intl.formatMessage({ id: 'pages.message.cluster.rollback.submitted' }));
history.push(`${fullPath}`);
const { run: runRollback, loading } = useRequest((prID: number) => createPipelineRun(id, {
action: 'rollback',
pipelinerunID: prID,
}), {
onSuccess: (pr: PIPELINES.Pipeline) => {
history.push(`/instances${fullPath}/-/pipelines/${pr.id}`);
window.location.reload();
},
manual: true,
});
Expand Down
4 changes: 2 additions & 2 deletions src/services/clusters.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ declare namespace CLUSTER {
};

type PipelineRunCreate = {
action: 'builddeploy' | 'deploy' | 'rollback'
title: string,
action: 'builddeploy' | 'deploy' | 'rollback' | 'restart'
title?: string,
description?: string;
git?: {
branch: string;
Expand Down

0 comments on commit 3ccc661

Please sign in to comment.