feat: 增强多实例分布式部署兼容
- 增加定时任务分布式锁并覆盖 chatlog、文档导入和 Agent HITL 过期扫描 - 增强 Redis MQ 多实例 consumer 标识、pending reclaim 和单条处理能力 - 增加文档导入状态 Redis 广播和 Agent HITL 跨节点路由确认
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package tech.easyflow.agent.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Agent 运行态生产化配置。
|
||||
@@ -15,6 +17,36 @@ public class AgentRuntimeProperties {
|
||||
*/
|
||||
private Duration sessionCacheTtl = Duration.ofHours(24);
|
||||
|
||||
/**
|
||||
* 当前 Agent 运行实例 ID。
|
||||
*/
|
||||
private String instanceId = defaultInstanceId();
|
||||
|
||||
/**
|
||||
* Agent 运行路由 TTL。
|
||||
*/
|
||||
private Duration routeTtl = Duration.ofHours(24);
|
||||
|
||||
/**
|
||||
* Agent 运行命令 topic 前缀。
|
||||
*/
|
||||
private String commandTopicPrefix = "easyflow:agent-runtime-command";
|
||||
|
||||
/**
|
||||
* Agent 运行命令结果等待超时时间。
|
||||
*/
|
||||
private Duration commandResultTimeout = Duration.ofSeconds(5);
|
||||
|
||||
/**
|
||||
* Agent 运行命令结果缓存 TTL。
|
||||
*/
|
||||
private Duration commandResultTtl = Duration.ofMinutes(5);
|
||||
|
||||
/**
|
||||
* 当前进程启动代 ID。
|
||||
*/
|
||||
private final String bootId = UUID.randomUUID().toString();
|
||||
|
||||
/**
|
||||
* HITL pending 默认过期时间。
|
||||
*/
|
||||
@@ -53,6 +85,107 @@ public class AgentRuntimeProperties {
|
||||
this.sessionCacheTtl = sessionCacheTtl == null ? Duration.ofHours(24) : sessionCacheTtl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前 Agent 运行实例 ID。
|
||||
*
|
||||
* @return 实例 ID
|
||||
*/
|
||||
public String getInstanceId() {
|
||||
return instanceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前 Agent 运行实例 ID。
|
||||
*
|
||||
* @param instanceId 实例 ID
|
||||
*/
|
||||
public void setInstanceId(String instanceId) {
|
||||
this.instanceId = StringUtils.hasText(instanceId) ? instanceId.trim() : defaultInstanceId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 Agent 运行路由 TTL。
|
||||
*
|
||||
* @return 路由 TTL
|
||||
*/
|
||||
public Duration getRouteTtl() {
|
||||
return routeTtl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 Agent 运行路由 TTL。
|
||||
*
|
||||
* @param routeTtl 路由 TTL
|
||||
*/
|
||||
public void setRouteTtl(Duration routeTtl) {
|
||||
this.routeTtl = routeTtl == null ? Duration.ofHours(24) : routeTtl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 Agent 运行命令 topic 前缀。
|
||||
*
|
||||
* @return 命令 topic 前缀
|
||||
*/
|
||||
public String getCommandTopicPrefix() {
|
||||
return commandTopicPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 Agent 运行命令 topic 前缀。
|
||||
*
|
||||
* @param commandTopicPrefix 命令 topic 前缀
|
||||
*/
|
||||
public void setCommandTopicPrefix(String commandTopicPrefix) {
|
||||
this.commandTopicPrefix = StringUtils.hasText(commandTopicPrefix)
|
||||
? commandTopicPrefix.trim()
|
||||
: "easyflow:agent-runtime-command";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 Agent 运行命令结果等待超时时间。
|
||||
*
|
||||
* @return 等待超时时间
|
||||
*/
|
||||
public Duration getCommandResultTimeout() {
|
||||
return commandResultTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 Agent 运行命令结果等待超时时间。
|
||||
*
|
||||
* @param commandResultTimeout 等待超时时间
|
||||
*/
|
||||
public void setCommandResultTimeout(Duration commandResultTimeout) {
|
||||
this.commandResultTimeout = commandResultTimeout == null ? Duration.ofSeconds(5) : commandResultTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 Agent 运行命令结果缓存 TTL。
|
||||
*
|
||||
* @return 结果缓存 TTL
|
||||
*/
|
||||
public Duration getCommandResultTtl() {
|
||||
return commandResultTtl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 Agent 运行命令结果缓存 TTL。
|
||||
*
|
||||
* @param commandResultTtl 结果缓存 TTL
|
||||
*/
|
||||
public void setCommandResultTtl(Duration commandResultTtl) {
|
||||
this.commandResultTtl = commandResultTtl == null ? Duration.ofMinutes(5) : commandResultTtl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前进程启动代 ID。
|
||||
*
|
||||
* @return 启动代 ID
|
||||
*/
|
||||
public String getBootId() {
|
||||
return bootId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 HITL pending 默认过期时间。
|
||||
*
|
||||
@@ -124,4 +257,16 @@ public class AgentRuntimeProperties {
|
||||
public void setLockRenewInterval(Duration lockRenewInterval) {
|
||||
this.lockRenewInterval = lockRenewInterval == null ? Duration.ofMinutes(1) : lockRenewInterval;
|
||||
}
|
||||
|
||||
private static String defaultInstanceId() {
|
||||
String envInstanceId = System.getenv("EASYFLOW_INSTANCE_ID");
|
||||
if (StringUtils.hasText(envInstanceId)) {
|
||||
return envInstanceId.trim();
|
||||
}
|
||||
String hostName = System.getenv("HOSTNAME");
|
||||
if (StringUtils.hasText(hostName)) {
|
||||
return hostName.trim();
|
||||
}
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user