Skip to content

Commit

Permalink
optimization: 任务状态测试问题修复
Browse files Browse the repository at this point in the history
  • Loading branch information
ywywZhou authored and luofann committed Nov 29, 2023
1 parent 7cecc9a commit e0312da
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@
@change="onNodeCheckClick">
</bk-checkbox>
</template>
<!-- 节点循环次数 -->
<div v-if="node.loop > 1" :class="['task-status-icon task-node-loop', { 'loop-plural': node.loop > 9 }]">
<i :class="`common-icon-loading-${ node.loop > 9 ? 'oval' : 'round' }`"></i>
<span>{{ node.loop > 99 ? '99+' : node.loop }}</span>
</div>
<!-- 任务节点自动重试/手动重试 -->
<template v-if="node.mode === 'execute'">
<span v-if="node.retry - node.auto_skip > 0" class="error-handle-icon">
<span class="text">MR</span>
<span class="count">{{ node.retry - node.auto_skip }}</span>
</span>
<span v-if="node.auto_skip" class="error-handle-icon">
<span class="text">AR</span>
<span class="count">{{ node.auto_skip }}</span>
</span>
</template>
<template v-else>
<span v-if="node.error_ignorable" class="error-handle-icon"><span class="text">AS</span></span>
<span v-if="node.isSkipped || node.skippable" class="error-handle-icon"><span class="text">MS</span></span>
<span v-if="node.can_retry || node.retryable" class="error-handle-icon"><span class="text">MR</span></span>
<span v-if="node.auto_retry && node.auto_retry.enable" class="error-handle-icon"><span class="text">AR</span></span>
</template>
</div>
<div v-if="node.hasUpdated" class="updated-dot">
<div class="ripple"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,12 @@
&:first-child {
margin-left: -4px;
}
&:nth-of-type(3) {
margin-left: -3px;
}
&:nth-of-type(4) {
margin-left: -2px;
}
}
}
.state-icon {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
</bk-select>
<span>{{$t('次执行')}}</span>
</div>
<p class="retry-details-tips" v-if="realTimeState.state === 'FAILED' && realTimeState.retry">
<p class="retry-details-tips" v-if="realTimeState.retry">
{{ $t('已自动重试 m 次 (最多 c 次),手动重试 n 次', autoRetryInfo)}}
</p>
</section>
Expand Down
48 changes: 21 additions & 27 deletions frontend/desktop/src/pages/task/TaskExecute/TaskOperation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@
sidebarWidth: 960,
nodeInfoType: '',
state: '', // 当前流程状态,画布切换时会更新
rootState: '', // 根流程状态
selectedNodeId: '',
selectedFlowPath: path, // 选择面包屑路径
cacheStatus: undefined, // 总任务缓存状态信息;只有总任务完成、终止时才存在
Expand Down Expand Up @@ -461,10 +460,6 @@
nodeNav () {
return this.selectedFlowPath.filter(item => item.type !== 'ServiceActivity')
},
// 当前画布是否为最外层
isTopTask () {
return this.nodeNav.length === 1
},
taskOperationBtns () {
const operationBtns = []
const operationType = STATE_OPERATIONS[this.state]
Expand All @@ -483,7 +478,6 @@
if (
this.state === 'CREATED'
&& this.unclaimFuncTask
&& this.isTopTask
&& this.creatorName !== this.username
) {
executePauseBtn.disabled = true
Expand All @@ -508,7 +502,7 @@
},
pendingNodes () {
const { children = {} } = this.instanceStatus
const pendingStatus = ['PENDING_PROCESSING', 'PENDING_APPROVAL', 'PENDING_CONFIRMATION']
const pendingStatus = ['FAILED', 'PENDING_PROCESSING', 'PENDING_APPROVAL', 'PENDING_CONFIRMATION']
return Object.values(children).reduce((acc, cur) => {
if (pendingStatus.includes(cur.state)) {
acc.push({
Expand All @@ -523,11 +517,11 @@
}
},
watch: {
instanceStatus: {
handler (val) {
const { state, children = {} } = val
'instanceStatus.state': {
handler (val, oldVal) {
const { children = {} } = this.instanceStatus
const { activities, gateways, flows, start_event, end_event } = tools.deepClone(this.pipelineData)
if (state === 'SUSPENDED') {
if (val !== oldVal && [val, oldVal].includes('SUSPENDED')) {
Object.values(children).forEach(node => {
// 非任务节点/网关节点
if ([start_event.id, end_event.id].includes(node.id)) return
Expand All @@ -538,7 +532,7 @@
}
outgoing.forEach(outLine => {
const targetNode = flows[outLine].target
const isExecuted = targetNode in children
const isExecuted = val === 'SUSPENDED' ? targetNode in children : true
// 输出节点未被执行则表明任务暂停后该分支在当前节点停止往下继续执行
this.setLineSuspendState(node.id, outLine, isExecuted)
})
Expand Down Expand Up @@ -620,31 +614,30 @@
project_id: this.project_id,
cancelToken: source.token
}
if (!this.isTopTask) {
data.instance_id = this.instance_id
data.subprocess_id = this.taskId
}
instanceStatus = await this.getInstanceStatus(data)
}
// 处理返回数据
if (instanceStatus.result) {
this.state = instanceStatus.data.state
this.instanceStatus = instanceStatus.data
this.pollErrorTimes = 0
if (this.isTopTask) {
this.rootState = this.state
}
if (
!this.cacheStatus
&& ['FINISHED', 'REVOKED'].includes(this.state)
&& this.taskId === this.instance_id
) { // save cacheStatus
this.cacheStatus = instanceStatus.data
}
let continueRunning = false
// 任务暂停时如果有节点正在执行,需轮询节点状态
let suspendedRunning = false
if (this.state === 'SUSPENDED') {
suspendedRunning = Object.values(instanceStatus.data.children).some(item => item.state === 'RUNNING')
const pendingStatus = ['RUNNING', 'PENDING_PROCESSING', 'PENDING_APPROVAL', 'PENDING_CONFIRMATION']
continueRunning = Object.values(instanceStatus.data.children).some(item => pendingStatus.includes(item.state))
}
// 任务失败时如果又节点还没自动重试完,需轮询节点状态
if (this.state === 'FAILED') {
const { auto_retry_infos: retryInfos = {} } = instanceStatus.data
continueRunning = Object.values(retryInfos).some(item => item.max_auto_retry_times > item.auto_retry_times)
}
// 节点执行记录显示时,重新计算当前执行时间/判断是否还在执行中
if (this.isExecRecordOpen) {
Expand All @@ -662,7 +655,7 @@
this.nodeExecRecordInfo.state = execNodeConfig.state
}
}
if (this.state === 'RUNNING' || (!this.isTopTask && this.state === 'FINISHED' && !['FINISHED', 'REVOKED', 'FAILED'].includes(this.rootState)) || suspendedRunning) {
if (['RUNNING', 'PENDING_PROCESSING'].includes(this.state) || continueRunning) {
if (this.isExecRecordOpen && this.nodeExecRecordInfo.state) { // 节点执行中一秒查一次
this.setTaskStatusTimer(1000)
} else {
Expand Down Expand Up @@ -1419,9 +1412,9 @@
return
}
this.approval.pending = true
this.$refs.approvalForm.validate().then(async () => {
try {
this.approval.pending = true
const { id, is_passed, message } = this.approval
const params = {
is_passed,
Expand All @@ -1448,6 +1441,8 @@
} finally {
this.approval.pending = false
}
}, () => {
this.approval.pending = false
})
},
onApprovalCancel () {
Expand Down Expand Up @@ -1512,13 +1507,13 @@
case 'reExecute':
return true
case 'execute':
return this.state === 'CREATED' && this.isTopTask
return this.state === 'CREATED'
case 'pause':
return ['RUNNING', 'NODE_SUSPENDED'].includes(this.state)
case 'resume':
return this.state === 'SUSPENDED'
case 'revoke':
return this.isTopTask && ['RUNNING', 'SUSPENDED', 'PENDING_PROCESSING', 'FAILED'].includes(this.state)
return ['RUNNING', 'SUSPENDED', 'PENDING_PROCESSING', 'FAILED'].includes(this.state)
default:
break
}
Expand Down Expand Up @@ -2102,7 +2097,6 @@
if (
action === 'execute'
&& this.unclaimFuncTask
&& this.isTopTask
&& this.creatorName === this.username
) {
const h = this.$createElement
Expand Down Expand Up @@ -2484,7 +2478,7 @@
},
unclickableOperation (type) {
// 失败时不允许点击暂停按钮,创建是不允许点击终止按钮,操作执行过程不允许点击
return (this.state === 'FAILED' && type !== 'revoke') || (this.state === 'CREATED' && type === 'revoke') || this.operateLoading || !this.isTopTask
return (this.state === 'FAILED' && type !== 'revoke') || (this.state === 'CREATED' && type === 'revoke') || this.operateLoading
},
packUp () {
this.isNodeInfoPanelShow = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<i class="bk-icon icon-arrows-left back-icon" @click="onBack"></i>
<span v-if="stateStr" :class="['task-state', state]" v-bk-tooltips="taskStatusDetailTipsConfig">
{{ stateStr }}
<i v-if="state === 'PENDING_PROCESSING'" class="common-icon-info"></i>
<i v-if="isStateDetailShow" class="common-icon-info"></i>
</span>
<dl class="task-state-detail" id="task-state-detail">
<dl v-show="stateStr && isStateDetailShow" class="task-state-detail" id="task-state-detail">
<dt>{{$t('状态明细')}}</dt>
<template v-if="pendingNodes.length">
<dd
Expand Down Expand Up @@ -145,7 +145,10 @@
computed: {
...mapState({
view_mode: state => state.view_mode
})
}),
isStateDetailShow () {
return ['FAILED', 'PENDING_PROCESSING'].includes(this.state)
}
},
watch: {
nodeNav (val) {
Expand Down Expand Up @@ -269,6 +272,7 @@
}
}
.task-state {
flex-shrink: 0;
display: inline-block;
margin: 0 8px;
padding: 0 8px;
Expand Down Expand Up @@ -305,6 +309,10 @@
&.FAILED {
background-color: #f2d0d3;
color: #ea3636;
i {
font-size: 14px;
color: #ea3636;
}
}
&.REVOKED {
background-color: #f2d0d3;
Expand Down

0 comments on commit e0312da

Please sign in to comment.