Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions lib/server/controller/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 11 additions & 1 deletion lib/server/service/business/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,24 @@ 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)
throw new Error(err.message, -1)
}
}

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) => {
Expand Down