Skip to content

Commit fb1d465

Browse files
committed
[waterflow] 修改检视意见
1 parent cc35ed4 commit fb1d465

File tree

4 files changed

+46
-37
lines changed

4 files changed

+46
-37
lines changed

app-builder/jane/plugins/aipp-plugin/src/main/java/modelengine/fit/jober/aipp/util/CacheUtils.java

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import modelengine.fit.jober.aipp.common.exception.AippException;
1919
import modelengine.fit.jober.aipp.po.AppBuilderAppPo;
2020
import modelengine.fitframework.annotation.Component;
21+
import modelengine.fitframework.log.Logger;
2122
import modelengine.fitframework.util.CollectionUtils;
2223

2324
import java.util.List;
@@ -33,37 +34,30 @@
3334
*/
3435
@Component
3536
public class CacheUtils {
37+
private static final Logger log = Logger.get(CacheUtils.class);
3638
/**
3739
* 用于缓存appId to app
3840
*/
39-
public static final Cache<String, AppBuilderAppPo> APP_CACHE = Caffeine.newBuilder()
40-
.expireAfterAccess(48, TimeUnit.HOURS)
41-
.maximumSize(30)
42-
.build();
41+
public static final Cache<String, AppBuilderAppPo> APP_CACHE =
42+
Caffeine.newBuilder().expireAfterAccess(48, TimeUnit.HOURS).maximumSize(30).build();
4343

4444
/**
4545
* 用于缓存flowDefinitionId to flowInfo
4646
*/
47-
public static final Cache<String, FlowInfo> FLOW_CACHE = Caffeine.newBuilder()
48-
.expireAfterAccess(48, TimeUnit.HOURS)
49-
.maximumSize(30)
50-
.build();
47+
public static final Cache<String, FlowInfo> FLOW_CACHE =
48+
Caffeine.newBuilder().expireAfterAccess(48, TimeUnit.HOURS).maximumSize(30).build();
5149

5250
/**
5351
* 用于缓存app_id和aipp_id的关系
5452
*/
55-
public static final Cache<String, String> APP_ID_TO_AIPP_ID_CACHE = Caffeine.newBuilder()
56-
.expireAfterAccess(30, TimeUnit.DAYS)
57-
.maximumSize(1000)
58-
.build();
53+
public static final Cache<String, String> APP_ID_TO_AIPP_ID_CACHE =
54+
Caffeine.newBuilder().expireAfterAccess(30, TimeUnit.DAYS).maximumSize(1000).build();
5955

6056
/**
61-
* 用于缓存app_id和meta的关系
57+
* 用于缓存app_id和最新发布的meta关系
6258
*/
63-
public static final Cache<String, Meta> AIPP_ID_LAST_META_CACHE = Caffeine.newBuilder()
64-
.expireAfterAccess(5, TimeUnit.SECONDS)
65-
.maximumSize(1000)
66-
.build();
59+
private static final Cache<String, Meta> AIPP_ID_TO_LAST_META_CACHE =
60+
Caffeine.newBuilder().expireAfterAccess(5, TimeUnit.SECONDS).maximumSize(1000).build();
6761

6862
/**
6963
* 清理缓存
@@ -72,44 +66,45 @@ public static void clear() {
7266
APP_CACHE.invalidateAll();
7367
FLOW_CACHE.invalidateAll();
7468
APP_ID_TO_AIPP_ID_CACHE.invalidateAll();
75-
AIPP_ID_LAST_META_CACHE.invalidateAll();
69+
AIPP_ID_TO_LAST_META_CACHE.invalidateAll();
7670

7771
APP_CACHE.cleanUp();
7872
FLOW_CACHE.cleanUp();
7973
APP_ID_TO_AIPP_ID_CACHE.cleanUp();
80-
AIPP_ID_LAST_META_CACHE.cleanUp();
74+
AIPP_ID_TO_LAST_META_CACHE.cleanUp();
8175
}
8276

8377
/**
8478
* 用于获取flowdefinition的缓存
8579
*
86-
* @param flowsService 操作flow的service
80+
* @param flowsService 操作flow的service
8781
* @param flowDefinitionId 缓存的flowDefinition的id
88-
* @param context 人员上下文
82+
* @param context 人员上下文
8983
* @return 缓存的FlowInfo
9084
*/
9185
public static FlowInfo getPublishedFlowWithCache(FlowsService flowsService, String flowDefinitionId,
92-
OperationContext context) {
86+
OperationContext context) {
9387
return FLOW_CACHE.get(flowDefinitionId, id -> flowsService.getFlows(id, context));
9488
}
9589

9690
/**
9791
* 根据appId查询对应meta
9892
*
9993
* @param metaService 用于查询meta的服务实例
100-
* @param appId 应用appId
101-
* @param isDebug 是否为debug会话
102-
* @param context 操作上下文
94+
* @param appId 应用appId
95+
* @param isDebug 是否为debug会话
96+
* @param context 操作上下文
10397
* @return app对应的meta信息
10498
*/
10599
public static Meta getMetaByAppId(MetaService metaService, String appId, boolean isDebug,
106-
OperationContext context) {
100+
OperationContext context) {
107101
if (isDebug) {
108102
return getLatestMetaByAppId(metaService, appId, context);
109103
}
110-
// get一个aipp_id的缓存,然后根据aipp_id查询最新发布版的meta
111-
String aippId = APP_ID_TO_AIPP_ID_CACHE.get(appId, id -> getLatestMetaByAppId(metaService, id, context).getId());
112-
return AIPP_ID_LAST_META_CACHE.get(aippId, (ignore) -> {
104+
// 获取一个aipp_id的缓存,然后根据aipp_id查询最新发布版的meta。
105+
String aippId =
106+
APP_ID_TO_AIPP_ID_CACHE.get(appId, id -> getLatestMetaByAppId(metaService, id, context).getId());
107+
return AIPP_ID_TO_LAST_META_CACHE.get(aippId, (ignore) -> {
113108
Meta lastPublishedMeta = MetaUtils.getLastPublishedMeta(metaService, appId, context);
114109
return Optional.ofNullable(lastPublishedMeta)
115110
.orElseThrow(() -> new AippException(AippErrCode.APP_CHAT_PUBLISHED_META_NOT_FOUND));
@@ -119,6 +114,7 @@ public static Meta getMetaByAppId(MetaService metaService, String appId, boolean
119114
private static Meta getLatestMetaByAppId(MetaService metaService, String appId, OperationContext context) {
120115
List<Meta> metas = MetaUtils.getAllMetasByAppId(metaService, appId, context);
121116
if (CollectionUtils.isEmpty(metas)) {
117+
log.error("No metas found for appId: " + appId);
122118
throw new AippException(AippErrCode.APP_CHAT_DEBUG_META_NOT_FOUND);
123119
}
124120
return metas.get(0);

app-builder/jane/services/aipp-service/src/main/java/modelengine/fit/jober/aipp/dto/chat/CreateAppChatRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class CreateAppChatRequest {
4242
/**
4343
* 判断是否有@应用
4444
*
45-
* @return true-有; false-没有
45+
* @return 表示是否有@应用的 {@link boolean}
4646
*/
4747
public boolean hasAtOtherApp() {
4848
return StringUtils.isNotBlank(getContext().getAtChatId()) || StringUtils.isNotBlank(getContext().getAtAppId());

app-builder/waterflow/java/waterflow-service/src/main/java/modelengine/fit/waterflow/common/utils/UUIDUtil.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
* Uuid的Utils类。
1414
*
1515
* @author 孙怡菲
16-
* @since 1.0
16+
* @since 2025-04-09
1717
*/
1818
public class UUIDUtil {
1919
/**
2020
* 随机生成uuid。
2121
*
22-
* @return 随机生成的uuid的 {@link String}。
22+
* @return 表示随机生成的uuid的 {@link String}。
2323
*/
2424
public static String uuid() {
2525
return UUID.randomUUID().toString().replace("-", "");
@@ -29,7 +29,7 @@ public static String uuid() {
2929
* 使用线程本地随机数生成UUID。
3030
* 生成的 UUID 在唯一性和不可预测性上可能不如 UUID.randomUUID(),但在性能上有显著提升
3131
*
32-
* @return 生成的UUID
32+
* @return 表示随机生成UUID的 {@link String}
3333
*/
3434
public static String fastUuid() {
3535
long mostSigBits = ThreadLocalRandom.current().nextLong();

app-builder/waterflow/java/waterflow-service/src/main/java/modelengine/fit/waterflow/flowsengine/biz/service/scheduletasks/CleanContextSchedule.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* 包括成功、失败、终止的流程数据
2424
*
2525
* @author 杨祥宇
26-
* @since 2025/04/02
26+
* @since 2025-04-02
2727
*/
2828
@Component
2929
public class CleanContextSchedule {
@@ -42,21 +42,34 @@ public CleanContextSchedule(FlowTraceRepo flowTraceRepo, @Fit(alias = "flowConte
4242

4343
/**
4444
* 每天凌晨3点定时清理超期EXPIRED_DAYS天的流程运行数据
45+
* 多实例并发执行分析:会并发执行getExpiredTrace()查询,可能导致重复获取相同traceIds
46+
* 重复删除trace以及context数据不会对结果有影响
47+
*
4548
*/
4649
@Scheduled(strategy = Scheduled.Strategy.CRON, value = "0 0 3 * * ?")
47-
@Transactional
4850
public void cleanContextSchedule() {
4951
log.info("Start clean flow expired contexts");
5052
try {
5153
List<String> traceIds = flowTraceRepo.getExpiredTrace(expiredDays, LIMIT);
5254
while (!traceIds.isEmpty()) {
53-
flowContextRepo.deleteByTraceIdList(traceIds);
54-
flowTraceRepo.deleteByIdList(traceIds);
55+
deleteFlowContext(traceIds);
5556
traceIds = flowTraceRepo.getExpiredTrace(expiredDays, LIMIT);
5657
SleepUtil.sleep(60000);
5758
}
5859
} catch (Exception ex) {
5960
log.error("Clean context error, error message: {}" + ex.getMessage());
6061
}
6162
}
63+
64+
/**
65+
* 根据traceId列表删除trace和context数据
66+
*
67+
* @param traceIds 表示流程trace id列表的{@link List}{@code <}{@link String}{@code >}。
68+
*/
69+
@Transactional
70+
public void deleteFlowContext(List<String> traceIds) {
71+
flowContextRepo.deleteByTraceIdList(traceIds);
72+
flowTraceRepo.deleteByIdList(traceIds);
73+
}
74+
6275
}

0 commit comments

Comments
 (0)