perf: 支持终断批量快捷命令执行的任务

This commit is contained in:
wangruidong
2024-03-13 18:04:19 +08:00
committed by Bryan
parent da90b23f99
commit 02b71619de

View File

@@ -57,7 +57,7 @@ import Page from '@/layout/components/Page'
import AdhocOpenDialog from '@/views/ops/Job/AdhocOpenDialog'
import AdhocSaveDialog from '@/views/ops/Job/AdhocSaveDialog'
import VariableHelpDialog from '@/views/ops/Job/VariableHelpDialog'
import { createJob, getJob, getTaskDetail } from '@/api/ops'
import { createJob, StopJob, getJob, getTaskDetail } from '@/api/ops'
export default {
name: 'CommandExecution',
@@ -110,6 +110,20 @@ export default {
this.execute()
}
},
stop: {
type: 'button',
name: this.$t('common.Stop'),
align: 'left',
icon: 'fa fa-stop',
tip: this.$t('ops.StopJob'),
disabled: true,
el: {
type: 'danger'
},
callback: () => {
this.stop()
}
},
runas: {
type: 'input',
name: this.$t('ops.runAs'),
@@ -343,9 +357,6 @@ export default {
switch (event) {
case 'end':
setTimeout(() => {
clearInterval(this.executionInfo.cancel)
this.toolbar.left.run.icon = 'fa fa-play'
this.toolbar.left.run.disabled = false
this.getTaskStatus()
}, 500)
break
@@ -356,6 +367,7 @@ export default {
getTaskStatus() {
getTaskDetail(this.currentTaskId).then(data => {
this.executionInfo.status = data['status']
this.setBtn()
})
},
wrapperError(msg) {
@@ -434,7 +446,26 @@ export default {
this.$router.replace({ query: { taskId: this.currentTaskId }})
this.setCostTimeInterval()
this.writeExecutionOutput()
this.setBtn()
})
},
stop() {
StopJob({ task_id: this.currentTaskId }).then(() => {
this.xterm.write(this.wrapperError('Task has been canceled'))
this.getTaskStatus()
}).catch((e) => {
console.log(e)
}).finally(() => {
this.setBtn()
})
},
setBtn() {
if (this.executionInfo.status !== 'running') {
clearInterval(this.executionInfo.cancel)
this.toolbar.left.run.icon = 'fa fa-play'
}
this.toolbar.left.run.disabled = this.executionInfo.status === 'running'
this.toolbar.left.stop.disabled = this.executionInfo.status !== 'running'
}
}
}