【feature】https://gitee.com/dromara/liteFlow/issues/I8B0MI 关于此 issue 中的并行日志进行优化,并行流程使用【】进行包裹

This commit is contained in:
韩华锋 2023-11-02 12:55:22 +08:00
parent e50082b7d6
commit 85a4d5243b
3 changed files with 41 additions and 2 deletions

View File

@ -1,6 +1,7 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
*
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
@ -14,6 +15,6 @@ package com.yomahub.liteflow.enums;
*/
public enum CmpStepTypeEnum {
START, END, SINGLE;
START, END, SINGLE, THEN_START, THEN_END;
}

View File

@ -8,13 +8,17 @@
package com.yomahub.liteflow.flow.element.condition;
import com.yomahub.liteflow.common.LocalDefaultFlowConstant;
import com.yomahub.liteflow.enums.CmpStepTypeEnum;
import com.yomahub.liteflow.enums.ConditionTypeEnum;
import com.yomahub.liteflow.enums.ParallelStrategyEnum;
import com.yomahub.liteflow.flow.element.Condition;
import com.yomahub.liteflow.flow.entity.CmpStep;
import com.yomahub.liteflow.flow.parallel.strategy.ParallelStrategyExecutor;
import com.yomahub.liteflow.flow.parallel.strategy.ParallelStrategyHelper;
import com.yomahub.liteflow.log.LFLog;
import com.yomahub.liteflow.log.LFLoggerManager;
import com.yomahub.liteflow.slot.DataBus;
import com.yomahub.liteflow.slot.Slot;
import com.yomahub.liteflow.thread.ExecutorHelper;
import java.util.Set;
@ -64,13 +68,15 @@ public class WhenCondition extends Condition {
// 使用线程池执行 when 并发流程
// 这块涉及到挺多的多线程逻辑所以注释比较详细看到这里的童鞋可以仔细阅读
private void executeAsyncCondition(Integer slotIndex) throws Exception {
Slot slot = DataBus.getSlot(slotIndex);
slot.addStep(new CmpStep("-1", "-1", CmpStepTypeEnum.THEN_START));
// 获取并发执行策略
ParallelStrategyExecutor parallelStrategyExecutor = ParallelStrategyHelper.loadInstance().buildParallelExecutor(this.getParallelStrategy());
// 执行并发逻辑
parallelStrategyExecutor.execute(this, slotIndex);
slot.addStep(new CmpStep("-1", "-1", CmpStepTypeEnum.THEN_END));
}
public boolean isIgnoreError() {

View File

@ -1,6 +1,7 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
*
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
@ -11,6 +12,7 @@ import cn.hutool.core.collection.ConcurrentHashSet;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.enums.CmpStepTypeEnum;
import com.yomahub.liteflow.exception.NoSuchContextBeanException;
import com.yomahub.liteflow.exception.NullParamException;
import com.yomahub.liteflow.flow.element.Condition;
@ -340,6 +342,21 @@ public class Slot {
CmpStep cmpStep;
for (Iterator<CmpStep> it = executeSteps.iterator(); it.hasNext();) {
cmpStep = it.next();
if (CmpStepTypeEnum.THEN_START.equals(cmpStep.getStepType())) {
str.append("");
continue;
}
if (CmpStepTypeEnum.THEN_END.equals(cmpStep.getStepType())) {
// 如果最后一个是==>则移除最后一个==>
if (str.toString().endsWith("==>")) {
str.delete(str.length() - 3, str.length());
}
str.append("");
if (it.hasNext()) {
str.append("==>");
}
continue;
}
if (withTimeSpent) {
str.append(cmpStep.buildStringWithTime());
}
@ -376,6 +393,21 @@ public class Slot {
CmpStep cmpStep;
for (Iterator<CmpStep> it = rollbackSteps.iterator(); it.hasNext();) {
cmpStep = it.next();
if (CmpStepTypeEnum.THEN_START.equals(cmpStep.getStepType())) {
str.append("");
continue;
}
if (CmpStepTypeEnum.THEN_END.equals(cmpStep.getStepType())) {
// 如果最后一个是==>则移除最后一个==>
if (str.toString().endsWith("==>")) {
str.delete(str.length() - 3, str.length());
}
str.append("");
if (it.hasNext()) {
str.append("==>");
}
continue;
}
if (withRollbackTimeSpent) {
str.append(cmpStep.buildRollbackStringWithTime());
}