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 Oct 30, 2023
1 parent cd2caa2 commit e8bfd9b
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<!-- 节点右上角执行相关的icon区域 -->
<node-right-icon-status :node="node"></node-right-icon-status>
<!-- tooltip提示(任务终止时禁止节点操作) -->
<div class="state-icon" :class="{ 'subprocess-operate': isSubProcessNode }">
<div class="state-icon" :class="{ 'subprocess-operate': isSubProcessNode && node.status === 'FAILED' }">
<template v-if="node.task_state !== 'REVOKED'">
<template v-if="node.status === 'FAILED' && node.type === 'tasknode'">
<span v-if="isShowRetryBtn" @click.stop="$emit('onRetryClick', node.id)">
Expand All @@ -55,17 +55,17 @@
{{ $t('跳过子流程') }}
</span>
</template>
<template v-if="!isSubProcessNode && node.status === 'RUNNING'">
<template v-if="node.status === 'RUNNING'">
<span @click.stop="onSubflowPauseResumeClick('pause')">
<i class="common-icon-mandatory-failure"></i>
{{ $t('暂停') }}
</span>
<span v-if="hasAdminPerm" @click.stop="$emit('onForceFail', node.id)">
<span v-if="isSubProcessNode" @click.stop="$emit('onForceFail', node.id)">
<i class="common-icon-resume"></i>
{{ $t('强制终止') }}
</span>
</template>
<span v-if="!isSubProcessNode && node.status === 'SUSPENDED'" @click.stop="onSubflowPauseResumeClick('resume')">
<span v-if="node.status === 'SUSPENDED'" @click.stop="onSubflowPauseResumeClick('resume')">
<i class="common-icon-play"></i>
{{ $t('继续') }}
</span>
Expand Down
20 changes: 15 additions & 5 deletions frontend/desktop/src/pages/task/TaskExecute/ExecuteInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
</div>
</div>
<div class="action-wrapper" v-if="isShowActionWrap">
<template v-if="executeInfo.state === 'RUNNING' && !isSubProcessNode">
<template v-if="executeInfo.state === 'RUNNING'">
<bk-button
v-if="nodeDetailConfig.component_code === 'pause_node'"
theme="primary"
Expand All @@ -188,7 +188,7 @@
{{ $t('强制终止') }}
</bk-button>
<bk-button
v-if="isLegacySubProcess"
v-if="isLegacySubProcess || isSubProcessNode"
data-test-id="taskExecute_form_pauseBtn"
@click="onPauseClick">
{{ $t('暂停') }}
Expand Down Expand Up @@ -439,7 +439,7 @@
isShowActionWrap () {
// 任务终止时禁止节点操作
if (this.state === 'REVOKED') return false
return (this.realTimeState.state === 'RUNNING' && !this.isSubProcessNode)
return this.realTimeState.state === 'RUNNING'
|| this.isShowRetryBtn
|| this.isShowSkipBtn
|| this.isShowContinueBtn
Expand Down Expand Up @@ -1425,7 +1425,12 @@
this.$emit('onSkipClick', this.nodeDetailConfig.node_id, info)
},
onResumeClick () {
this.$emit('onTaskNodeResumeClick', this.nodeDetailConfig.node_id, this.subProcessTaskId)
if (this.isSubProcessNode) {
const taskId = this.executeInfo.outputs.find(item => item.key === 'task_id') || {}
this.$emit('onTaskNodeResumeClick', this.nodeDetailConfig.node_id, taskId.value, true)
} else {
this.$emit('onTaskNodeResumeClick', this.nodeDetailConfig.node_id, this.subProcessTaskId)
}
},
onApprovalClick () {
this.$emit('onApprovalClick', this.nodeDetailConfig.node_id, this.subProcessTaskId)
Expand All @@ -1437,7 +1442,12 @@
this.$emit('onForceFail', this.nodeDetailConfig.node_id, this.subProcessTaskId)
},
onPauseClick () {
this.$emit('onPauseClick', this.nodeDetailConfig.node_id, this.subProcessTaskId)
if (this.isSubProcessNode) {
const taskId = this.executeInfo.outputs.find(item => item.key === 'task_id') || {}
this.$emit('onPauseClick', this.nodeDetailConfig.node_id, taskId.value, true)
} else {
this.$emit('onPauseClick', this.nodeDetailConfig.node_id, this.subProcessTaskId)
}
},
onContinueClick () {
this.$emit('onContinueClick', this.nodeDetailConfig.node_id, this.subProcessTaskId)
Expand Down
97 changes: 75 additions & 22 deletions frontend/desktop/src/pages/task/TaskExecute/TaskOperation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@
'getNodeExecutionRecord',
'getNodeActInfo',
'instanceRetry',
'getNodeActDetail',
'subflowNodeRetry',
'taskFlowConvertCommonTask'
]),
Expand Down Expand Up @@ -748,21 +749,30 @@
this.pending.task = false
}
},
async taskPause (subflowPause, nodeId, taskId) {
/**
* nodeId 子流程节点id
* taskId 子流程任务id, 不传则是最外层任务暂停
* independent 是否为独立子流程节点
*/
async taskPause (nodeId, taskId, independent) {
let res, state, message
try {
if (!this.isTopTask || subflowPause) { // 子流程画布暂停或子流程节点暂停
const instanceId = taskId || this.instance_id
if (nodeId && !independent) { // 非独立子流程节点暂停
const data = {
instance_id: taskId || this.instance_id,
node_id: nodeId || this.taskId
instance_id: instanceId,
node_id: nodeId
}
res = await this.subInstancePause(data)
} else { // 任务暂停/独立子流程任务暂停
res = await this.instancePause(instanceId)
}
if (nodeId || taskId) {
state = 'NODE_SUSPENDED'
const { activities } = this.pipelineData
const { name } = activities[nodeId]
const { name } = activities[nodeId] || this.activities[nodeId] || {}
message = name + ' ' + i18n.t('节点已暂停执行')
} else {
res = await this.instancePause(this.instance_id)
state = 'SUSPENDED'
message = i18n.t('任务已暂停执行')
}
Expand All @@ -780,20 +790,24 @@
this.pending.task = false
}
},
async taskResume (subflowResume, nodeId, taskId) {
async taskResume (nodeId, taskId, independent) {
let res, message
try {
if (!this.isTopTask || subflowResume) {
const instanceId = taskId || this.instance_id
if (nodeId && !independent) { // 非独立子流程节点继续执行
const data = {
instance_id: taskId || this.instance_id,
node_id: nodeId || this.taskId
instance_id: instanceId,
node_id: nodeId
}
res = await this.subInstanceResume(data)
} else { // 任务继续执行/独立子流程任务继续执行
res = await this.instanceResume(this.instance_id)
}
if (nodeId || taskId) {
const { activities } = this.pipelineData
const { name } = activities[nodeId]
const { name } = activities[nodeId] || this.activities[nodeId] || {}
message = name + ' ' + i18n.t('节点已继续执行')
} else {
res = await this.instanceResume(this.instance_id)
message = i18n.t('任务已继续执行')
}
if (res.result) {
Expand Down Expand Up @@ -865,11 +879,31 @@
}
this.pending.forceFail = true
try {
const params = {
node_id: id,
task_id: Number(taskId || this.instance_id)
let res = {}
// 强制终止独立子流程任务节点
const nodeConfig = this.activities[id]
const isSubProcessNode = nodeConfig.component?.code === 'subprocess_plugin'
if (isSubProcessNode) {
if (!taskId) {
const resp = await this.getNodeActDetail({
instance_id: this.instance_id,
node_id: id,
component_code: 'subprocess_plugin',
subprocess_simple_inputs: true
})
if (!resp.result) return
const { outputs = [] } = resp.data
const data = outputs.find(item => item.key === 'task_id') || {}
taskId = data.value
}
res = await this.instanceRevoke(taskId)
} else {
const params = {
node_id: id,
task_id: Number(taskId || this.instance_id)
}
res = await this.forceFail(params)
}
const res = await this.forceFail(params)
if (res.result) {
this.$bkMessage({
message: i18n.t('强制终止执行成功'),
Expand Down Expand Up @@ -1354,16 +1388,16 @@
this.approval.message = ''
this.approval.dialogShow = false
},
onPauseClick (id, taskId) {
this.taskPause(true, id, taskId)
onPauseClick (id, taskId, independent) {
this.taskPause(id, taskId, independent)
this.isNodeInfoPanelShow = false
this.nodeInfoType = ''
setTimeout(() => {
this.setTaskStatusTimer()
}, 1000)
},
onContinueClick (id, taskId) {
this.taskResume(true, id, taskId)
onContinueClick (id, taskId, independent) {
this.taskResume(id, taskId, independent)
this.isNodeInfoPanelShow = false
this.nodeInfoType = ''
setTimeout(() => {
Expand All @@ -1373,9 +1407,28 @@
onCloseConfigPanel () {
this.isShowConditionEdit = false
},
onSubflowPauseResumeClick (id, value) {
async onSubflowPauseResumeClick (id, value) {
if (this.pending.subflowPause) return
value === 'pause' ? this.taskPause(true, id) : this.taskResume(true, id)
try {
const nodeConfig = this.activities[id]
const isSubProcessNode = nodeConfig.component?.code === 'subprocess_plugin'
if (isSubProcessNode) {
const resp = await this.getNodeActDetail({
instance_id: this.instance_id,
node_id: id,
component_code: 'subprocess_plugin',
subprocess_simple_inputs: true
})
if (!resp.result) return
const { outputs = [] } = resp.data
const taskId = outputs.find(item => item.key === 'task_id') || {}
value === 'pause' ? this.taskPause(id, taskId.value, true) : this.taskResume(id, taskId.value, true)
} else {
value === 'pause' ? this.taskPause(id) : this.taskResume(id)
}
} catch (error) {
console.warn(error)
}
},
// 设置画布数据,更新页面
setCanvasData () {
Expand Down

0 comments on commit e8bfd9b

Please sign in to comment.