diff --git a/lib/server/controller/flow.js b/lib/server/controller/flow.js index a9aa0342e..d76988b5d 100644 --- a/lib/server/controller/flow.js +++ b/lib/server/controller/flow.js @@ -33,7 +33,7 @@ import { LCDataService, TABLE_FILE_NAME } from '../service/common/data-service' import httpConf from '../conf/http' import v3Conf from '../conf/v3' import { transFlowTplToBkFlowPipelineTree } from '../utils/flow' -import { getTaskList } from '../service/business/flow' +import { getLesscodeBkFlowSpaceId, getTaskList } from '../service/business/flow' const bkflowApiGatewayName = global.BKFLOW_API_GATEWAY_NAME const authorization = { @@ -539,7 +539,7 @@ export default class FlowController { const taskName = `${flowDetail.name}_${dayjs().format('YYYYMMDDHHmmss')}` const notifyConfig = JSON.parse(flowDetail.notifyConfig) - const { bkFlowSpaceId } = await LCDataService.findOne(TABLE_FILE_NAME.PROJECT_BKFLOW_SPACE, { projectId: 0 }) + const bkFlowSpaceId = await getLesscodeBkFlowSpaceId() const bkFlowTaskDetail = await execApiGateWay({ apiName: bkflowApiGatewayName, @@ -624,7 +624,7 @@ export default class FlowController { const taskIds = list.map(item => item.bkFlowTaskId) - const { bkFlowSpaceId } = await LCDataService.findOne(TABLE_FILE_NAME.PROJECT_BKFLOW_SPACE, { projectId: 0 }) + const bkFlowSpaceId = await getLesscodeBkFlowSpaceId() // 调用BkFlow接口查询任务的执行状态 const tasksStatusRes = await execApiGateWay({ @@ -688,7 +688,7 @@ export default class FlowController { const taskIds = list.map(item => item.bkFlowTaskId) - const { bkFlowSpaceId } = await LCDataService.findOne(TABLE_FILE_NAME.PROJECT_BKFLOW_SPACE, { projectId: 0 }) + const bkFlowSpaceId = await getLesscodeBkFlowSpaceId() // 调用BkFlow接口查询任务的执行状态 const tasksStatusRes = await execApiGateWay({ @@ -742,7 +742,9 @@ export default class FlowController { console.log('准备请求 =====') const pipelineTree = transFlowTplToBkFlowPipelineTree(projectId, nodes, edges) - const { bkFlowSpaceId } = await LCDataService.findOne(TABLE_FILE_NAME.PROJECT_BKFLOW_SPACE, { projectId: 0 }) + + const bkFlowSpaceId = await getLesscodeBkFlowSpaceId() + try { const res = await execApiGateWay({ apiName: bkflowApiGatewayName, @@ -786,7 +788,7 @@ export default class FlowController { ) { const runningNodeIds = [] const taskItem = await LCDataService.findOne(TABLE_FILE_NAME.FLOW_TASK, { id: taskId }) - const { bkFlowSpaceId } = await LCDataService.findOne(TABLE_FILE_NAME.PROJECT_BKFLOW_SPACE, { projectId: 0 }) + const bkFlowSpaceId = await getLesscodeBkFlowSpaceId() // 任务执行详情数据 const taskExecDetail = await execApiGateWay({ @@ -863,7 +865,7 @@ export default class FlowController { @PathParams({ name: 'taskId', require: true }) taskId, ) { const taskItem = await LCDataService.findOne(TABLE_FILE_NAME.FLOW_TASK, { id: taskId }) - const { bkFlowSpaceId } = await LCDataService.findOne(TABLE_FILE_NAME.PROJECT_BKFLOW_SPACE, { projectId: 0 }) + const bkFlowSpaceId = await getLesscodeBkFlowSpaceId() // 任务执行详情数据 const taskExecDetail = await execApiGateWay({ @@ -956,7 +958,7 @@ export default class FlowController { }) const taskItem = await LCDataService.findOne(TABLE_FILE_NAME.FLOW_TASK, { id: taskId }) - const { bkFlowSpaceId } = await LCDataService.findOne(TABLE_FILE_NAME.PROJECT_BKFLOW_SPACE, { projectId: 0 }) + const bkFlowSpaceId = await getLesscodeBkFlowSpaceId() const taskTplDetail = await execApiGateWay({ apiName: bkflowApiGatewayName, diff --git a/lib/server/service/business/flow.js b/lib/server/service/business/flow.js index 76064de29..435935dc2 100644 --- a/lib/server/service/business/flow.js +++ b/lib/server/service/business/flow.js @@ -55,6 +55,7 @@ export const createBkFlowSpace = async () => { projectId: 0, bkFlowSpaceId: response.data.space.id }) + return response.data.space.id } } catch (err) { console.error('create bkflow space error:\n', err) @@ -62,7 +63,16 @@ export const createBkFlowSpace = async () => { } } - return spaceData + return spaceData.bkFlowSpaceId +} + +// 获取lesscode平台在bkflow的空间id,如果不存在则创建一个 +export const getLesscodeBkFlowSpaceId = async () => { + const spaceData = await LCDataService.findOne(TABLE_FILE_NAME.PROJECT_BKFLOW_SPACE, { projectId: 0 }) + if (spaceData) { + return spaceData.bkFlowSpaceId + } + return await createBkFlowSpace() } export const getTaskList = (parmas) => {