大声道撒旦

This commit is contained in:
dengqichen 2024-12-25 19:00:18 +08:00
parent 963405defd
commit 0a249161dd
5 changed files with 67 additions and 34 deletions

View File

@ -11,4 +11,21 @@ public interface WorkFlowConstants {
String SEQUENCE_FLOW_ERROR_PREFIX = "SEQUENCE_FLOW_ERROR_";
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";
}

View File

@ -2,12 +2,20 @@ package com.qqchen.deploy.backend.workflow.delegate;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qqchen.deploy.backend.workflow.constants.WorkFlowConstants;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.BpmnError;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;
import org.flowable.common.engine.api.delegate.Expression;
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的转换和注入
@ -18,25 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
@Slf4j
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
private ObjectMapper objectMapper;
@ -68,15 +58,15 @@ public abstract class BaseNodeDelegate<P, L> implements JavaDelegate {
executeInternal(execution, panelVars, localVars);
// 如果节点没有设置状态默认设置成功状态
if (execution.getVariable(EXECUTION_STATUS) == null) {
setExecutionStatus(execution, STATUS_SUCCESS);
String status = getExecutionStatus(execution);
if (status == null) {
setExecutionStatus(execution, WORKFLOW_NODE_EXECUTION_STATUS_SUCCESS);
}
} catch (Exception e) {
// 设置失败状态
setExecutionStatus(execution, STATUS_FAILURE);
setExecutionStatus(execution, WORKFLOW_NODE_EXECUTION_STATUS_FAILURE);
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 状态值
*/
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);
}
@ -113,4 +103,17 @@ public abstract class BaseNodeDelegate<P, L> implements JavaDelegate {
* @param localVariables 转换后的Local变量
*/
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);
}
}

View File

@ -56,10 +56,10 @@ public class DeployNodeDelegate extends BaseNodeDelegate<DeployNodePanelVariable
@Override
protected void executeInternal(DelegateExecution execution, DeployNodePanelVariables panelVariables, DeployNodeLocalVariables localVariables) {
// String queueId = jenkinsServiceIntegration.buildWithParameters();
// JenkinsQueueBuildInfoResponse buildInfo = waitForBuildToStart(queueId);
// // 3. 轮询构建状态
// pollBuildStatus("scp-meta", buildInfo.getBuildNumber());
String queueId = jenkinsServiceIntegration.buildWithParameters();
JenkinsQueueBuildInfoResponse buildInfo = waitForBuildToStart(queueId);
// 3. 轮询构建状态
pollBuildStatus("scp-meta", buildInfo.getBuildNumber());
}
private JenkinsQueueBuildInfoResponse waitForBuildToStart(String queueId) {

View File

@ -63,12 +63,12 @@ public class NotificationNodeDelegate extends BaseNodeDelegate<NotificationNodeP
HttpEntity<String> entity = new HttpEntity<>(format, headers);
// restTemplate.exchange(
// WX_HOOK_API,
// HttpMethod.POST,
// entity,
// String.class
// );
restTemplate.exchange(
WX_HOOK_API,
HttpMethod.POST,
entity,
String.class
);
}
}

View File

@ -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.event.WorkflowNodeInstanceStatusChangeEvent;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
@ -12,6 +13,10 @@ import org.springframework.stereotype.Component;
import jakarta.annotation.Resource;
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
@Component("globalNodeExecutionListener")
@ -41,7 +46,15 @@ public class GlobalExecutionListener implements ExecutionListener {
startTime = now;
break;
case ExecutionListener.EVENTNAME_END:
status = WorkflowNodeInstanceStatusEnums.COMPLETED;
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;
} else {
status = WorkflowNodeInstanceStatusEnums.FAILED;
}
endTime = now;
break;
default: