Amy0104
3 years ago
committed by
GitHub
38 changed files with 667 additions and 321 deletions
@ -1,83 +0,0 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
import { omit } from 'lodash' |
||||
import type { IDataNode, ITask } from './types' |
||||
|
||||
export function useData({ |
||||
nodeData, |
||||
type, |
||||
taskDefinition |
||||
}: { |
||||
nodeData: IDataNode |
||||
type: string |
||||
taskDefinition?: ITask |
||||
}) { |
||||
const data = { |
||||
backfill: {}, |
||||
isCreate: false |
||||
} |
||||
|
||||
if (type === 'task-definition') { |
||||
if (taskDefinition) { |
||||
data.backfill = formatBackfill(taskDefinition, nodeData.taskType) |
||||
data.isCreate = false |
||||
} |
||||
} |
||||
|
||||
return { |
||||
code: nodeData.id |
||||
} |
||||
} |
||||
|
||||
export function formatBackfill(task: ITask, taskType: string) { |
||||
let strategy: string | undefined = task.timeoutNotifyStrategy |
||||
if (taskType === 'DEPENDENT' && task.timeoutNotifyStrategy === 'WARNFAILED') { |
||||
strategy = 'WARN,FAILED' |
||||
} |
||||
return { |
||||
code: task.code, |
||||
conditionResult: task.taskParams.conditionResult, |
||||
switchResult: task.taskParams.switchResult, |
||||
delayTime: task.delayTime, |
||||
dependence: task.taskParams.dependence, |
||||
desc: task.description, |
||||
id: task.id, |
||||
maxRetryTimes: task.failRetryTimes, |
||||
name: task.name, |
||||
params: omit(task.taskParams, [ |
||||
'conditionResult', |
||||
'dependence', |
||||
'waitStartTimeout', |
||||
'switchResult' |
||||
]), |
||||
retryInterval: task.failRetryInterval, |
||||
runFlag: task.flag, |
||||
taskInstancePriority: task.taskPriority, |
||||
timeout: { |
||||
interval: task.timeout, |
||||
strategy, |
||||
enable: task.timeoutFlag === 'OPEN' |
||||
}, |
||||
type: task.taskType, |
||||
waitStartTimeout: task.taskParams.waitStartTimeout, |
||||
workerGroup: task.workerGroup, |
||||
environmentCode: task.environmentCode, |
||||
taskGroupId: task.taskGroupId, |
||||
taskGroupPriority: task.taskGroupPriority |
||||
} |
||||
} |
@ -1,33 +0,0 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
import { reactive, ref } from 'vue' |
||||
|
||||
export function useDetail() { |
||||
const state = reactive({ |
||||
formRef: ref(), |
||||
loading: false, |
||||
saving: false |
||||
}) |
||||
|
||||
const onSubmit = async (model: object) => { |
||||
await state.formRef.validate() |
||||
} |
||||
return { |
||||
state, |
||||
onSubmit |
||||
} |
||||
} |
@ -0,0 +1,62 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
import { ref, onMounted } from 'vue' |
||||
import { useI18n } from 'vue-i18n' |
||||
import { querySimpleList } from '@/service/modules/process-definition' |
||||
import type { IJsonItem } from '../types' |
||||
|
||||
export function useProcessName( |
||||
projectCode: number, |
||||
isCreate: boolean |
||||
): IJsonItem { |
||||
const { t } = useI18n() |
||||
|
||||
const options = ref([] as { label: string; value: string }[]) |
||||
const loading = ref(false) |
||||
|
||||
const getProcessList = async () => { |
||||
if (loading.value) return |
||||
loading.value = true |
||||
try { |
||||
const res = await querySimpleList(projectCode) |
||||
options.value = res.map((option: { name: string; code: number }) => ({ |
||||
label: option.name, |
||||
value: option.code |
||||
})) |
||||
loading.value = false |
||||
} catch (err) { |
||||
loading.value = false |
||||
} |
||||
} |
||||
|
||||
onMounted(() => { |
||||
getProcessList() |
||||
}) |
||||
|
||||
return { |
||||
type: 'select', |
||||
field: 'processCode', |
||||
span: 24, |
||||
name: t('project.node.process_name'), |
||||
props: { |
||||
loading: loading, |
||||
disabled: !isCreate |
||||
}, |
||||
options: options |
||||
} |
||||
} |
@ -0,0 +1,48 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
import { useI18n } from 'vue-i18n' |
||||
import { TASK_TYPES_MAP } from '@/views/projects/task/constants/task-type' |
||||
import type { IJsonItem } from '../types' |
||||
|
||||
export function useTaskType( |
||||
model: { [field: string]: any }, |
||||
readonly?: boolean |
||||
): IJsonItem { |
||||
const { t } = useI18n() |
||||
|
||||
const options = Object.keys(TASK_TYPES_MAP).map((option: string) => ({ |
||||
label: option, |
||||
value: option |
||||
})) |
||||
return { |
||||
type: 'select', |
||||
field: 'taskType', |
||||
span: 24, |
||||
name: t('project.node.task_type'), |
||||
props: { |
||||
disabled: readonly || ['CONDITIONS', 'SWITCH'].includes(model.taskType) |
||||
}, |
||||
options: options, |
||||
validate: { |
||||
trigger: ['input', 'blur'], |
||||
required: true, |
||||
message: t('project.node.task_type_tips') |
||||
}, |
||||
value: 'SHELL' |
||||
} |
||||
} |
@ -0,0 +1,109 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
import { omit } from 'lodash' |
||||
import type { INodeData, ITaskData } from './types' |
||||
|
||||
export function formatParams(data: INodeData): { |
||||
processDefinitionCode: string |
||||
upstreamCodes: string |
||||
taskDefinitionJsonObj: object |
||||
} { |
||||
const params = { |
||||
processDefinitionCode: data.processCode ? String(data.processCode) : '', |
||||
upstreamCodes: '', |
||||
taskDefinitionJsonObj: { |
||||
...omit(data, [ |
||||
'processCode', |
||||
'delayTime', |
||||
'environmentCode', |
||||
'failRetryTimes', |
||||
'failRetryInterval', |
||||
'taskGroupId', |
||||
'localParams', |
||||
'timeoutFlag', |
||||
'timeoutNotifyStrategy', |
||||
'resourceList' |
||||
]), |
||||
code: data.code, |
||||
delayTime: data.delayTime ? '0' : String(data.delayTime), |
||||
environmentCode: data.environmentCode || -1, |
||||
failRetryTimes: data.failRetryTimes ? String(data.failRetryTimes) : '0', |
||||
failRetryInterval: data.failRetryTimes |
||||
? String(data.failRetryTimes) |
||||
: '0', |
||||
taskGroupId: data.taskGroupId || '', |
||||
taskParams: { |
||||
localParams: data.localParams, |
||||
rawScript: data.rawScript, |
||||
resourceList: data.resourceList?.length |
||||
? data.resourceList.map((id: number) => ({ id })) |
||||
: [] |
||||
}, |
||||
timeoutFlag: data.timeoutFlag ? 'OPEN' : 'CLOSE', |
||||
timeoutNotifyStrategy: data.timeoutNotifyStrategy?.join('') |
||||
} |
||||
} as { |
||||
processDefinitionCode: string |
||||
upstreamCodes: string |
||||
taskDefinitionJsonObj: { timeout: number; timeoutNotifyStrategy: string } |
||||
} |
||||
if (!data.timeoutFlag) { |
||||
params.taskDefinitionJsonObj.timeout = 0 |
||||
params.taskDefinitionJsonObj.timeoutNotifyStrategy = '' |
||||
} |
||||
return params |
||||
} |
||||
|
||||
export function formatModel(data: ITaskData) { |
||||
const params = { |
||||
name: data.name, |
||||
taskType: data.taskType, |
||||
processName: data.processName, |
||||
flag: data.flag, |
||||
description: data.description, |
||||
taskPriority: data.taskPriority, |
||||
workerGroup: data.workerGroup, |
||||
environmentCode: data.environmentCode === -1 ? null : data.environmentCode, |
||||
taskGroupId: data.taskGroupId, |
||||
taskGroupPriority: data.taskGroupPriority, |
||||
failRetryTimes: data.failRetryTimes, |
||||
failRetryInterval: data.failRetryInterval, |
||||
delayTime: data.delayTime, |
||||
timeoutFlag: data.timeoutFlag === 'OPEN', |
||||
timeoutNotifyStrategy: [data.timeoutNotifyStrategy] || [], |
||||
resourceList: data.taskParams.resourceList, |
||||
timeout: data.timeout, |
||||
rawScript: data.taskParams.rawScript, |
||||
localParams: data.taskParams.localParams, |
||||
preTasks: [], |
||||
id: data.id, |
||||
code: data.code |
||||
} as { |
||||
timeoutNotifyStrategy: string[] |
||||
resourceList: number[] |
||||
} |
||||
if (data.timeoutNotifyStrategy === 'WARNFAILED') { |
||||
params.timeoutNotifyStrategy = ['WARN', 'FAILED'] |
||||
} |
||||
if (data.taskParams.resourceList) { |
||||
params.resourceList = data.taskParams.resourceList.map( |
||||
(item: { id: number }) => item.id |
||||
) |
||||
} |
||||
return params |
||||
} |
@ -0,0 +1,97 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
import { reactive } from 'vue' |
||||
import { |
||||
genTaskCodeList, |
||||
saveSingle, |
||||
queryTaskDefinitionByCode, |
||||
updateWithUpstream |
||||
} from '@/service/modules/task-definition' |
||||
import { formatParams as formatData } from '../components/node/format-data' |
||||
import type { ITaskData, INodeData, ISingleSaveReq, IRecord } from './types' |
||||
|
||||
export function useTask(projectCode: number) { |
||||
const task = reactive({ |
||||
taskShow: false, |
||||
taskData: { |
||||
taskType: 'SHELL' |
||||
}, |
||||
taskSaving: false, |
||||
taskReadonly: false |
||||
} as { taskShow: boolean; taskData: ITaskData; taskSaving: boolean; taskReadonly: boolean }) |
||||
|
||||
const formatParams = (data: INodeData): ISingleSaveReq => { |
||||
const params = formatData(data) |
||||
return { |
||||
processDefinitionCode: params.processDefinitionCode, |
||||
upstreamCodes: params.upstreamCodes, |
||||
taskDefinitionJsonObj: JSON.stringify(params.taskDefinitionJsonObj) |
||||
} |
||||
} |
||||
|
||||
const getTaskCode = async () => { |
||||
const result = await genTaskCodeList(1, projectCode) |
||||
return result[0] |
||||
} |
||||
|
||||
const onToggleShow = (show: boolean) => { |
||||
task.taskShow = show |
||||
} |
||||
const onTaskSave = async (data: INodeData) => { |
||||
try { |
||||
if (task.taskSaving) return |
||||
task.taskSaving = true |
||||
if (data.id) { |
||||
data.code && |
||||
(await updateWithUpstream( |
||||
projectCode, |
||||
data.code, |
||||
formatParams({ ...data, code: data.code }) |
||||
)) |
||||
} else { |
||||
const taskCode = await getTaskCode() |
||||
await saveSingle(projectCode, formatParams({ ...data, code: taskCode })) |
||||
} |
||||
|
||||
task.taskSaving = false |
||||
return true |
||||
} catch (e) { |
||||
window.$message.error((e as Error).message) |
||||
task.taskSaving = false |
||||
return false |
||||
} |
||||
} |
||||
|
||||
const onEditTask = async (row: IRecord, readonly: boolean) => { |
||||
try { |
||||
const result = await queryTaskDefinitionByCode(row.taskCode, projectCode) |
||||
task.taskData = { ...result, processName: row.processDefinitionCode } |
||||
task.taskShow = true |
||||
task.taskReadonly = readonly |
||||
} catch (e) { |
||||
window.$message.error((e as Error).message) |
||||
} |
||||
} |
||||
|
||||
return { |
||||
task, |
||||
onToggleShow, |
||||
onTaskSave, |
||||
onEditTask |
||||
} |
||||
} |
Loading…
Reference in new issue