大声道撒旦
This commit is contained in:
parent
963405defd
commit
0a249161dd
@ -11,4 +11,21 @@ public interface WorkFlowConstants {
|
|||||||
String SEQUENCE_FLOW_ERROR_PREFIX = "SEQUENCE_FLOW_ERROR_";
|
String SEQUENCE_FLOW_ERROR_PREFIX = "SEQUENCE_FLOW_ERROR_";
|
||||||
|
|
||||||
String ASYNC_CONTINUATION = "async-continuation";
|
String ASYNC_CONTINUATION = "async-continuation";
|
||||||
|
|
||||||
|
String WORKFLOW_PREVIOUS_NODE_EXECUTION_STATUS_VARIABLE_NAME = "PREVIOUS_NODE_EXECUTION_STATUS";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行状态:成功
|
||||||
|
*/
|
||||||
|
String WORKFLOW_NODE_EXECUTION_STATUS_SUCCESS = "SUCCESS";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行状态:失败
|
||||||
|
*/
|
||||||
|
String WORKFLOW_NODE_EXECUTION_STATUS_FAILURE = "FAILURE";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行状态:中止
|
||||||
|
*/
|
||||||
|
String WORKFLOW_NODE_EXECUTION_STATUS_ABORTED = "ABORTED";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,12 +2,20 @@ package com.qqchen.deploy.backend.workflow.delegate;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.qqchen.deploy.backend.workflow.constants.WorkFlowConstants;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.flowable.engine.delegate.BpmnError;
|
||||||
import org.flowable.engine.delegate.DelegateExecution;
|
import org.flowable.engine.delegate.DelegateExecution;
|
||||||
import org.flowable.engine.delegate.JavaDelegate;
|
import org.flowable.engine.delegate.JavaDelegate;
|
||||||
import org.flowable.common.engine.api.delegate.Expression;
|
import org.flowable.common.engine.api.delegate.Expression;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import static com.qqchen.deploy.backend.workflow.constants.WorkFlowConstants.WORKFLOW_NODE_EXECUTION_STATUS_FAILURE;
|
||||||
|
import static com.qqchen.deploy.backend.workflow.constants.WorkFlowConstants.WORKFLOW_NODE_EXECUTION_STATUS_SUCCESS;
|
||||||
|
import static com.qqchen.deploy.backend.workflow.constants.WorkFlowConstants.WORKFLOW_PREVIOUS_NODE_EXECUTION_STATUS_VARIABLE_NAME;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 任务委派者基类
|
* 任务委派者基类
|
||||||
* 负责处理panelVariables和localVariables的转换和注入
|
* 负责处理panelVariables和localVariables的转换和注入
|
||||||
@ -18,25 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public abstract class BaseNodeDelegate<P, L> implements JavaDelegate {
|
public abstract class BaseNodeDelegate<P, L> implements JavaDelegate {
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行状态变量名
|
|
||||||
*/
|
|
||||||
protected static final String EXECUTION_STATUS = "executionStatus";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行状态:成功
|
|
||||||
*/
|
|
||||||
protected static final String STATUS_SUCCESS = "success";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行状态:失败
|
|
||||||
*/
|
|
||||||
protected static final String STATUS_FAILURE = "failure";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行状态:中止
|
|
||||||
*/
|
|
||||||
protected static final String STATUS_ABORTED = "aborted";
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ObjectMapper objectMapper;
|
private ObjectMapper objectMapper;
|
||||||
@ -68,15 +58,15 @@ public abstract class BaseNodeDelegate<P, L> implements JavaDelegate {
|
|||||||
executeInternal(execution, panelVars, localVars);
|
executeInternal(execution, panelVars, localVars);
|
||||||
|
|
||||||
// 如果节点没有设置状态,默认设置成功状态
|
// 如果节点没有设置状态,默认设置成功状态
|
||||||
if (execution.getVariable(EXECUTION_STATUS) == null) {
|
String status = getExecutionStatus(execution);
|
||||||
setExecutionStatus(execution, STATUS_SUCCESS);
|
if (status == null) {
|
||||||
|
setExecutionStatus(execution, WORKFLOW_NODE_EXECUTION_STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 设置失败状态
|
// 设置失败状态
|
||||||
setExecutionStatus(execution, STATUS_FAILURE);
|
setExecutionStatus(execution, WORKFLOW_NODE_EXECUTION_STATUS_FAILURE);
|
||||||
log.error("Task execution failed", e);
|
log.error("Task execution failed", e);
|
||||||
throw new RuntimeException("Task execution failed: " + e.getMessage(), e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +77,7 @@ public abstract class BaseNodeDelegate<P, L> implements JavaDelegate {
|
|||||||
* @param status 状态值
|
* @param status 状态值
|
||||||
*/
|
*/
|
||||||
protected void setExecutionStatus(DelegateExecution execution, String status) {
|
protected void setExecutionStatus(DelegateExecution execution, String status) {
|
||||||
execution.setVariable(EXECUTION_STATUS, status);
|
execution.setVariable(WORKFLOW_PREVIOUS_NODE_EXECUTION_STATUS_VARIABLE_NAME, status);
|
||||||
log.debug("Set execution status: {}", status);
|
log.debug("Set execution status: {}", status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,4 +103,17 @@ public abstract class BaseNodeDelegate<P, L> implements JavaDelegate {
|
|||||||
* @param localVariables 转换后的Local变量
|
* @param localVariables 转换后的Local变量
|
||||||
*/
|
*/
|
||||||
protected abstract void executeInternal(DelegateExecution execution, P panelVariables, L localVariables);
|
protected abstract void executeInternal(DelegateExecution execution, P panelVariables, L localVariables);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取执行状态
|
||||||
|
*
|
||||||
|
* @param execution 执行上下文
|
||||||
|
* @return 执行状态,如果不存在则返回null
|
||||||
|
*/
|
||||||
|
protected String getExecutionStatus(DelegateExecution execution) {
|
||||||
|
return Optional.ofNullable(execution.getVariables())
|
||||||
|
.map(vars -> vars.get(WORKFLOW_PREVIOUS_NODE_EXECUTION_STATUS_VARIABLE_NAME))
|
||||||
|
.map(Object::toString)
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -56,10 +56,10 @@ public class DeployNodeDelegate extends BaseNodeDelegate<DeployNodePanelVariable
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void executeInternal(DelegateExecution execution, DeployNodePanelVariables panelVariables, DeployNodeLocalVariables localVariables) {
|
protected void executeInternal(DelegateExecution execution, DeployNodePanelVariables panelVariables, DeployNodeLocalVariables localVariables) {
|
||||||
// String queueId = jenkinsServiceIntegration.buildWithParameters();
|
String queueId = jenkinsServiceIntegration.buildWithParameters();
|
||||||
// JenkinsQueueBuildInfoResponse buildInfo = waitForBuildToStart(queueId);
|
JenkinsQueueBuildInfoResponse buildInfo = waitForBuildToStart(queueId);
|
||||||
// // 3. 轮询构建状态
|
// 3. 轮询构建状态
|
||||||
// pollBuildStatus("scp-meta", buildInfo.getBuildNumber());
|
pollBuildStatus("scp-meta", buildInfo.getBuildNumber());
|
||||||
}
|
}
|
||||||
|
|
||||||
private JenkinsQueueBuildInfoResponse waitForBuildToStart(String queueId) {
|
private JenkinsQueueBuildInfoResponse waitForBuildToStart(String queueId) {
|
||||||
|
|||||||
@ -63,12 +63,12 @@ public class NotificationNodeDelegate extends BaseNodeDelegate<NotificationNodeP
|
|||||||
|
|
||||||
HttpEntity<String> entity = new HttpEntity<>(format, headers);
|
HttpEntity<String> entity = new HttpEntity<>(format, headers);
|
||||||
|
|
||||||
// restTemplate.exchange(
|
restTemplate.exchange(
|
||||||
// WX_HOOK_API,
|
WX_HOOK_API,
|
||||||
// HttpMethod.POST,
|
HttpMethod.POST,
|
||||||
// entity,
|
entity,
|
||||||
// String.class
|
String.class
|
||||||
// );
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package com.qqchen.deploy.backend.workflow.listener.execution;
|
|||||||
import com.qqchen.deploy.backend.workflow.enums.WorkflowNodeInstanceStatusEnums;
|
import com.qqchen.deploy.backend.workflow.enums.WorkflowNodeInstanceStatusEnums;
|
||||||
import com.qqchen.deploy.backend.workflow.event.WorkflowNodeInstanceStatusChangeEvent;
|
import com.qqchen.deploy.backend.workflow.event.WorkflowNodeInstanceStatusChangeEvent;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.flowable.bpmn.model.FlowElement;
|
import org.flowable.bpmn.model.FlowElement;
|
||||||
import org.flowable.engine.delegate.DelegateExecution;
|
import org.flowable.engine.delegate.DelegateExecution;
|
||||||
import org.flowable.engine.delegate.ExecutionListener;
|
import org.flowable.engine.delegate.ExecutionListener;
|
||||||
@ -12,6 +13,10 @@ import org.springframework.stereotype.Component;
|
|||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static com.qqchen.deploy.backend.workflow.constants.WorkFlowConstants.WORKFLOW_PREVIOUS_NODE_EXECUTION_STATUS_VARIABLE_NAME;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component("globalNodeExecutionListener")
|
@Component("globalNodeExecutionListener")
|
||||||
@ -41,7 +46,15 @@ public class GlobalExecutionListener implements ExecutionListener {
|
|||||||
startTime = now;
|
startTime = now;
|
||||||
break;
|
break;
|
||||||
case ExecutionListener.EVENTNAME_END:
|
case ExecutionListener.EVENTNAME_END:
|
||||||
|
String nodeExecutionStatus = Optional.ofNullable(execution.getVariables())
|
||||||
|
.map(vars -> vars.get(WORKFLOW_PREVIOUS_NODE_EXECUTION_STATUS_VARIABLE_NAME))
|
||||||
|
.map(Object::toString)
|
||||||
|
.orElse(null);
|
||||||
|
if (StringUtils.isEmpty(nodeExecutionStatus)) {
|
||||||
status = WorkflowNodeInstanceStatusEnums.COMPLETED;
|
status = WorkflowNodeInstanceStatusEnums.COMPLETED;
|
||||||
|
} else {
|
||||||
|
status = WorkflowNodeInstanceStatusEnums.FAILED;
|
||||||
|
}
|
||||||
endTime = now;
|
endTime = now;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user