feat(sj_1.0.0): 重试任务-完成初稿

This commit is contained in:
dhb52 2024-04-21 23:55:16 +08:00
parent d678b5acaa
commit c9ba6efc47
7 changed files with 161 additions and 31 deletions

View File

@ -44,17 +44,24 @@ const local: App.I18n.Schema = {
success: 'Success', success: 'Success',
fail: 'Fail', fail: 'Fail',
stop: 'Stop', stop: 'Stop',
execute: 'Execute',
resume: 'Resume',
pause: 'Pause',
finish: 'Finish',
running: 'Running', running: 'Running',
confirmStop: 'Are you sure you want to stop?', confirmExecute: 'Are you sure you want to execute?',
confirmResume: 'Are you sure you want to resume?',
confirmPause: 'Are you sure you want to pause?',
confirmFinish: 'Are you sure you want to finishe?',
yesOrNo: { yesOrNo: {
yes: 'Yes', yes: 'Yes',
no: 'No' no: 'No'
}, },
systemTaskType: { systemTaskType: {
retry: '重试任务', retry: 'Retry task',
callback: '回调任务', callback: 'Callback task',
job: '定时任务', job: 'Job task',
workflow: '工作流' workflow: 'Workflow'
} }
}, },
request: { request: {

View File

@ -44,8 +44,15 @@ const local: App.I18n.Schema = {
success: '成功', success: '成功',
fail: '失败', fail: '失败',
stop: '停止', stop: '停止',
execute: '执行',
resume: '恢复',
pause: '暂停',
finish: '完成',
running: '运行中', running: '运行中',
confirmStop: '确认停止吗?', confirmExecute: '确认执行吗?',
confirmResume: '确认恢复吗?',
confirmPause: '确认暂停吗?',
confirmFinish: '确认完成吗?',
yesOrNo: { yesOrNo: {
yes: '是', yes: '是',
no: '否' no: '否'

View File

@ -44,3 +44,21 @@ export function fetchUpdateRetryTaskStatus(data: Api.RetryTask.RetryTaskUpdateSt
data data
}); });
} }
/** manual execute retryTask */
export function fetchExecuteRetryTask(data: Api.RetryTask.ManualTriggerTaskRequestVO) {
return request<boolean>({
url: '/retry-task/manual/trigger/retry/task',
method: 'post',
data
});
}
/** batch delete retryTask */
export function fetchBatchDeleteRetryTask(data: Api.RetryTask.BatchDeleteRetryTaskVO) {
return request<number>({
url: '/retry-task/batch',
method: 'delete',
data
});
}

12
src/typings/api.d.ts vendored
View File

@ -669,6 +669,16 @@ declare namespace Api {
retryStatus: RetryStatusType; retryStatus: RetryStatusType;
}; };
type ManualTriggerTaskRequestVO = {
groupName: string;
uniqueIds: string[];
};
type BatchDeleteRetryTaskVO = {
groupName: string;
ids: string[];
};
/** RetryTask search params */ /** RetryTask search params */
type RetryTaskSearchParams = CommonType.RecordNullable< type RetryTaskSearchParams = CommonType.RecordNullable<
Pick<Api.RetryTask.RetryTask, 'uniqueId' | 'groupName' | 'sceneName' | 'idempotentId' | 'bizNo' | 'retryStatus'> & Pick<Api.RetryTask.RetryTask, 'uniqueId' | 'groupName' | 'sceneName' | 'idempotentId' | 'bizNo' | 'retryStatus'> &
@ -703,7 +713,7 @@ declare namespace Api {
/** 最大重试次数 */ /** 最大重试次数 */
maxRetryCount: number; maxRetryCount: number;
/** 间隔时间 */ /** 间隔时间 */
triggerInterval: string; triggerInterval: number;
/** 调用链超时时间 */ /** 调用链超时时间 */
deadlineRequest: number; deadlineRequest: number;
/** 超时时间 */ /** 超时时间 */

View File

@ -290,8 +290,15 @@ declare namespace App {
success: string; success: string;
fail: string; fail: string;
stop: string; stop: string;
execute: string;
resume: string;
pause: string;
finish: string;
running: string; running: string;
confirmStop: string; confirmExecute: string;
confirmResume: string;
confirmPause: string;
confirmFinish: string;
yesOrNo: { yesOrNo: {
yes: string; yes: string;
no: string; no: string;

View File

@ -75,7 +75,7 @@ function createDefaultModel(): Model {
sceneStatus: 1, sceneStatus: 1,
backOff: 2, backOff: 2,
maxRetryCount: 1, maxRetryCount: 1,
triggerInterval: '60', triggerInterval: 60,
deadlineRequest: 60000, deadlineRequest: 60000,
executorTimeout: 60, executorTimeout: 60,
description: '', description: '',

View File

@ -1,7 +1,12 @@
<script setup lang="tsx"> <script setup lang="tsx">
import { NButton, NPopconfirm, NTag } from 'naive-ui'; import { NButton, NPopconfirm, NTag } from 'naive-ui';
import { useBoolean } from '@sa/hooks'; import { useBoolean } from '@sa/hooks';
import { fetchGetRetryTaskList, fetchUpdateRetryTaskStatus } from '@/service/api'; import {
fetchBatchDeleteRetryTask,
fetchExecuteRetryTask,
fetchGetRetryTaskList,
fetchUpdateRetryTaskStatus
} from '@/service/api';
import { $t } from '@/locales'; import { $t } from '@/locales';
import { useAppStore } from '@/store/modules/app'; import { useAppStore } from '@/store/modules/app';
import { useTable, useTableOperate } from '@/hooks/common/table'; import { useTable, useTableOperate } from '@/hooks/common/table';
@ -121,13 +126,13 @@ const { columns, columnChecks, data, getData, loading, mobilePagination, searchP
key: 'operate', key: 'operate',
title: $t('common.operate'), title: $t('common.operate'),
align: 'center', align: 'center',
width: 130, width: 260,
render: row => ( render: row => (
<div class="flex-center gap-8px"> <div class="flex-center gap-8px">
<NButton type="primary" ghost size="small" onClick={() => edit(row.id!)}> <NButton type="primary" ghost size="small" onClick={() => edit(row.id!)}>
{$t('common.edit')} {$t('common.edit')}
</NButton> </NButton>
<NPopconfirm onPositiveClick={() => handleDelete(row.id!)}> <NPopconfirm onPositiveClick={() => handleDelete(row.groupName!, row.id!)}>
{{ {{
default: () => $t('common.confirmDelete'), default: () => $t('common.confirmDelete'),
trigger: () => ( trigger: () => (
@ -137,16 +142,66 @@ const { columns, columnChecks, data, getData, loading, mobilePagination, searchP
) )
}} }}
</NPopconfirm> </NPopconfirm>
<NPopconfirm onPositiveClick={() => handleStop(Number(row.id!), row.groupName!)}> {/* 非[完成,最大次数], 显示[执行]按钮 */}
{{ {row.retryStatus !== 1 && row.retryStatus !== 2 ? (
default: () => $t('common.confirmStop'), <NPopconfirm onPositiveClick={() => handleExecute(row.groupName!, row.uniqueId!)}>
trigger: () => ( {{
<NButton type="error" ghost size="small"> default: () => $t('common.confirmExecute'),
{$t('common.stop')} trigger: () => (
</NButton> <NButton type="error" ghost size="small">
) {$t('common.execute')}
}} </NButton>
</NPopconfirm> )
}}
</NPopconfirm>
) : (
''
)}
{/* 非[完成,最大次数], 显示[完成]按钮 */}
{row.retryStatus !== 1 && row.retryStatus !== 2 ? (
<NPopconfirm onPositiveClick={() => handleFinish(Number(row.id!), row.groupName!)}>
{{
default: () => $t('common.confirmFinish'),
trigger: () => (
<NButton type="error" ghost size="small">
{$t('common.finish')}
</NButton>
)
}}
</NPopconfirm>
) : (
''
)}
{/* 重试中, 显示[停止]按钮 */}
{row.retryStatus === 0 ? (
<NPopconfirm onPositiveClick={() => handlePause(Number(row.id!), row.groupName!)}>
{{
default: () => $t('common.confirmPause'),
trigger: () => (
<NButton type="error" ghost size="small">
{$t('common.pause')}
</NButton>
)
}}
</NPopconfirm>
) : (
''
)}
{/* 暂停, 显示[开始]按钮 */}
{row.retryStatus === 3 ? (
<NPopconfirm onPositiveClick={() => handleResume(Number(row.id!), row.groupName!)}>
{{
default: () => $t('common.confirmResume'),
trigger: () => (
<NButton type="error" ghost size="small">
{$t('common.resume')}
</NButton>
)
}}
</NPopconfirm>
) : (
''
)}
</div> </div>
) )
} }
@ -160,19 +215,30 @@ const {
handleAdd, handleAdd,
handleEdit, handleEdit,
checkedRowKeys, checkedRowKeys,
onBatchDeleted,
onDeleted onDeleted
// closeDrawer // closeDrawer
} = useTableOperate(data, getData); } = useTableOperate(data, getData);
const { bool: batchAddDrawerVisible, setTrue: openBatchAddDrawer } = useBoolean(); const { bool: batchAddDrawerVisible, setTrue: openBatchAddDrawer } = useBoolean();
function handleDelete(id: string) { async function handleDelete(groupName: string, id: string) {
// request const { error } = await fetchBatchDeleteRetryTask({ groupName, ids: [id] });
console.log(id); if (error) return;
onDeleted(); onDeleted();
} }
async function handleBatchDelete() {
const ids: string[] = checkedRowKeys.value as string[];
if (ids.length === 0) return;
const groupName = data.value[0].groupName;
const { error } = await fetchBatchDeleteRetryTask({ groupName, ids });
if (error) return;
onBatchDeleted();
}
function edit(id: string) { function edit(id: string) {
handleEdit(id); handleEdit(id);
} }
@ -181,13 +247,27 @@ function handleBatchAdd() {
openBatchAddDrawer(); openBatchAddDrawer();
} }
async function handleStop(id: number, groupName: string) { function handleExecute(groupName: string, uniqueId: string) {
const { error } = await fetchUpdateRetryTaskStatus({ id, groupName, retryStatus: 3 }); fetchExecuteRetryTask({ groupName, uniqueIds: [uniqueId] });
if (error) { }
window.$message?.error($t('common.updateFailed'));
return; function handleResume(id: number, groupName: string) {
} updateRetryTaskStatus(id, groupName, 0);
}
function handlePause(id: number, groupName: string) {
updateRetryTaskStatus(id, groupName, 3);
}
function handleFinish(id: number, groupName: string) {
updateRetryTaskStatus(id, groupName, 1);
}
async function updateRetryTaskStatus(id: number, groupName: string, retryStatus: Api.RetryTask.RetryStatusType) {
const { error } = await fetchUpdateRetryTaskStatus({ id, groupName, retryStatus });
if (error) return;
window.$message?.success($t('common.updateSuccess')); window.$message?.success($t('common.updateSuccess'));
getData();
} }
</script> </script>
@ -208,6 +288,7 @@ async function handleStop(id: number, groupName: string) {
:loading="loading" :loading="loading"
@add="handleAdd" @add="handleAdd"
@batch-add="handleBatchAdd" @batch-add="handleBatchAdd"
@delete="handleBatchDelete"
@refresh="getData" @refresh="getData"
/> />
</template> </template>