update 优化 liteflow 整体上下文用法优化
This commit is contained in:
+1
-1
@@ -14,7 +14,7 @@ public class ContextRequiredComponent extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
if (getRequestData() == null) {
|
||||
if (getFirstContextBean() == null) {
|
||||
throw new ServiceException("LiteFlow 上下文不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -27,8 +27,8 @@ public class FailComponent extends NodeComponent {
|
||||
* @return 失败提示
|
||||
*/
|
||||
private String getFailMessage() {
|
||||
Object requestData = getRequestData();
|
||||
if (requestData instanceof FailMessageProvider provider) {
|
||||
Object context = getFirstContextBean();
|
||||
if (context instanceof FailMessageProvider provider) {
|
||||
String message = provider.getFailMessage();
|
||||
if (StringUtils.isNotBlank(message)) {
|
||||
return message;
|
||||
|
||||
+9
-2
@@ -4,6 +4,7 @@ import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
|
||||
@@ -12,19 +13,25 @@ import org.dromara.common.core.utils.SpringUtils;
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Slf4j
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class LiteFlowUtils {
|
||||
|
||||
/**
|
||||
* 执行 LiteFlow 链路,并按业务异常语义透传失败原因。
|
||||
* 执行 LiteFlow 链路,并按 contextBean 语义透传业务上下文和失败原因。
|
||||
*
|
||||
* @param chainId 链路标识
|
||||
* @param context 链路上下文
|
||||
*/
|
||||
public static void execute(String chainId, Object context) {
|
||||
LiteflowResponse response = SpringUtils.getBean(FlowExecutor.class).execute2Resp(chainId, context);
|
||||
if (context == null) {
|
||||
throw new ServiceException("LiteFlow 上下文不能为空");
|
||||
}
|
||||
LiteflowResponse response = SpringUtils.getBean(FlowExecutor.class).execute2Resp(chainId, null, context);
|
||||
if (!response.isSuccess()) {
|
||||
Exception cause = response.getCause();
|
||||
log.error("LiteFlow 链路执行失败 chainId={} requestId={} message={} steps={}",
|
||||
chainId, response.getRequestId(), response.getMessage(), response.getExecuteStepStrWithTime(), cause);
|
||||
if (cause instanceof RuntimeException runtimeException) {
|
||||
throw runtimeException;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user