refactor(websocket): 重构 WebSocket 服务端
- 优化 CsWsClientManager 类,改用 clientMap 存储客户端连接 - 重构 CsWsMessage 类,将 bizType 改为 bizCode - 优化 CsWsServer 类,增加任务线程管理功能 - 重构 PipelineInstanceService 接口,修改 queryLastPipelineDetailWs 方法参数 - 优化 PipelineInstanceServiceImpl 中的查询逻辑 - 更新前端 WebSocket 连接逻辑,采用新的 sid 格式
This commit is contained in:
@@ -11,7 +11,7 @@ export default {
|
||||
* @param confirmCallBack 确认回调
|
||||
* @param cancelCallBack 取消回调
|
||||
*/
|
||||
FullConfirm(questionText, msgType, confirmCallBack, cancelCallBack) {
|
||||
FullConfirm: function(questionText, msgType, confirmCallBack, cancelCallBack) {
|
||||
let currentType = 'info'
|
||||
if (msgType === 's') {
|
||||
currentType = 'success'
|
||||
@@ -38,7 +38,7 @@ export default {
|
||||
* @param confirmCallBack 确认回调
|
||||
* @param cancelCallBack 取消回调
|
||||
*/
|
||||
DeleteConfirm(confirmCallBack, cancelCallBack) {
|
||||
DeleteConfirm: function(confirmCallBack, cancelCallBack) {
|
||||
this.FullConfirm('确定删除本条数据吗?', 'w', confirmCallBack, cancelCallBack)
|
||||
}, /**
|
||||
* 数据删除确认对话框(自定义提示内容)
|
||||
@@ -46,7 +46,7 @@ export default {
|
||||
* @param confirmCallBack 确认回调
|
||||
* @param cancelCallBack 取消回调
|
||||
*/
|
||||
DeleteMessageConfirm(message, confirmCallBack, cancelCallBack) {
|
||||
DeleteMessageConfirm: function(message, confirmCallBack, cancelCallBack) {
|
||||
this.FullConfirm(message, 'w', confirmCallBack, cancelCallBack)
|
||||
}, /**
|
||||
* 数据输入对话框
|
||||
@@ -56,7 +56,7 @@ export default {
|
||||
* @param confirmCallBack 校验通过回调
|
||||
* @param cancelCallBack 取消回调
|
||||
*/
|
||||
TextInputConfirm(title, patternText, errorMsg, confirmCallBack, cancelCallBack) {
|
||||
TextInputConfirm: function(title, patternText, errorMsg, confirmCallBack, cancelCallBack) {
|
||||
Vue.prototype.$prompt('', title, {
|
||||
confirmButtonText: '确定', cancelButtonText: '取消', inputPattern: patternText, inputErrorMessage: errorMsg
|
||||
}).then(({ value }) => {
|
||||
@@ -73,7 +73,7 @@ export default {
|
||||
* @param title 标题
|
||||
* @param content 内容
|
||||
*/
|
||||
ShowConfirm(title, content) {
|
||||
ShowConfirm: function(title, content) {
|
||||
Vue.prototype.$alert(content, title, {
|
||||
confirmButtonText: '关闭'
|
||||
})
|
||||
|
||||
@@ -3,22 +3,22 @@ import Vue from 'vue'
|
||||
* 消息提示
|
||||
*/
|
||||
export default {
|
||||
Info(content) {
|
||||
Info: function(content) {
|
||||
Vue.prototype.$message({
|
||||
message: content, type: 'info'
|
||||
})
|
||||
},
|
||||
Success(content) {
|
||||
Success: function(content) {
|
||||
Vue.prototype.$message({
|
||||
message: content, type: 'success'
|
||||
})
|
||||
},
|
||||
Warning(content) {
|
||||
Warning: function(content) {
|
||||
Vue.prototype.$message({
|
||||
message: content, type: 'warning'
|
||||
})
|
||||
},
|
||||
Error(content) {
|
||||
Error: function(content) {
|
||||
Vue.prototype.$message({
|
||||
message: content, type: 'error'
|
||||
})
|
||||
|
||||
@@ -4,17 +4,17 @@ import Vue from 'vue'
|
||||
* 通知
|
||||
*/
|
||||
export default {
|
||||
Info(content) {
|
||||
Info: function(content) {
|
||||
Vue.prototype.$notify({ message: content, type: 'info' })
|
||||
}, Success(content) {
|
||||
}, Success: function(content) {
|
||||
Vue.prototype.$notify({ message: content, type: 'success' })
|
||||
}, SuccessDuration(content, durationTime) {
|
||||
}, SuccessDuration: function(content, durationTime) {
|
||||
Vue.prototype.$notify({ message: content, type: 'success', duration: durationTime })
|
||||
}, Warning(content) {
|
||||
}, Warning: function(content) {
|
||||
Vue.prototype.$notify({ message: content, type: 'warning' })
|
||||
}, Error(content) {
|
||||
}, Error: function(content) {
|
||||
Vue.prototype.$notify({ message: content, type: 'error' })
|
||||
}, ErrorDuration(content, durationTime) {
|
||||
}, ErrorDuration: function(content, durationTime) {
|
||||
Vue.prototype.$notify({ message: content, type: 'error', duration: durationTime })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ import { queryLastPipelineDetail, queryLastPipelineDetailWs, startPipeline } fro
|
||||
import { CountArraysObjectByPropKey, FormatDateTimeStr } from '@/utils/CsUtil'
|
||||
import CsMessage from '@/utils/elementui/CsMessage'
|
||||
import CsWsClient from '@/utils/CsWsClient'
|
||||
import { mapGetters } from 'vuex'
|
||||
|
||||
export default {
|
||||
name: 'CutePipelineNodeDemo',
|
||||
@@ -472,6 +473,11 @@ export default {
|
||||
// }
|
||||
// this.connectWebSocketServer(pipelineInstanceId)
|
||||
},
|
||||
computed: {
|
||||
...mapGetters([
|
||||
'user'
|
||||
])
|
||||
},
|
||||
methods: {
|
||||
refreshData() {
|
||||
// 成功
|
||||
@@ -509,7 +515,8 @@ export default {
|
||||
*/
|
||||
connectWebSocketServer(instanceId) {
|
||||
const that = this
|
||||
const sid = 'instanceId_' + instanceId
|
||||
// {username}_{bizCode}_{contextParams}
|
||||
const sid = `${that.user.username}_FetchPipelineLastDetail_${instanceId}`
|
||||
that.dynamicWsClient = new CsWsClient(sid)
|
||||
that.dynamicWsClient.connect(that.handleWebSocketError, that.handleWebSocketMessage)
|
||||
setTimeout(() => {
|
||||
@@ -533,11 +540,17 @@ export default {
|
||||
// 判断流水线是否结束
|
||||
const successCount = CountArraysObjectByPropKey(that.dynamicInstance.nodes, 'status', 'success')
|
||||
if (that.dynamicTemplate && that.dynamicTemplate.length === successCount) {
|
||||
// 所有节点执行成功
|
||||
if (that.dynamicWsClient) {
|
||||
that.dynamicWsClient.close()
|
||||
}
|
||||
that.dynamicStartupStatus = that.dynamicStartupStatusMap.start.code
|
||||
} else {
|
||||
const failCount = CountArraysObjectByPropKey(that.dynamicInstance.nodes, 'status', 'fail')
|
||||
// 存在失败的节点
|
||||
if (that.dynamicWsClient && failCount > 0) {
|
||||
that.dynamicWsClient.close()
|
||||
}
|
||||
that.dynamicStartupStatus = that.dynamicStartupStatusMap.restart.code
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -594,8 +607,9 @@ export default {
|
||||
CsMessage.Success('流水线启动成功')
|
||||
// await that.fetchLastDetail(result.instanceId)
|
||||
sessionStorage.setItem('pipelineInstanceId', result.instanceId)
|
||||
this.connectWebSocketServer(result.instanceId)
|
||||
that.connectWebSocketServer(result.instanceId)
|
||||
} catch (e) {
|
||||
console.error('error', e)
|
||||
that.dynamicStartButtonLoading = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ import LineChart from './dashboard/LineChart'
|
||||
import RadarChart from '@/components/Echarts/RadarChart'
|
||||
import PieChart from '@/components/Echarts/PieChart'
|
||||
import BarChart from '@/components/Echarts/BarChart'
|
||||
import CsMessage from '@/utils/elementui/CsMessage'
|
||||
|
||||
const lineChartData = {
|
||||
newVisitis: {
|
||||
|
||||
Reference in New Issue
Block a user