feat(collect-routing): 专利/货源本地采集开关与 Linux 兜底窗口
外观专利与相似ASIN默认「本地采集」,由页面推本机客户端;本地推了没人领时
PENDING 超过 linux-fallback-minutes(默认 30 分钟)才允许 Linux 内部认领接管,
避免本地机全关时任务无限排队(PENDING 已不再按时间判死)。
- 新增 aiimage.collect-routing.local-enabled 与 GET /api/collect-routing
- 客户端兜底拉取只认本地模块;内部认领对本地模块按兜底窗口二次过滤
- 外观专利 activate 在本地模式下恢复 PENDING→RUNNING 条件更新(与认领互斥),
关闭时保留后台拒绝语义;相似ASIN 关闭时明确拒绝「点启动」
- 恢复 GET /api/appearance-patent/tasks/{id}/queue-payload(本地推送取载荷用)
- /api/collect-routing 进用户态守卫名单,两处前缀计数基线 15→16 / 23→24
This commit is contained in:
@@ -112,6 +112,9 @@ public class AdminApiGuardFilter extends OncePerRequestFilter {
|
||||
// items 与 result(app_client/amazon/add_product.py:973,1048),所以带 JWT 的
|
||||
// 请求一旦被解析出身份就得按会话归属对齐,匿名执行器路径行为不变。
|
||||
"/api/publish",
|
||||
// 2026-10-29 采集路由开关读取口(GET /api/collect-routing):用户工具端点,
|
||||
// 新建即入名单,没有历史匿名调用方(前端两个工具页登录后读取)。
|
||||
"/api/collect-routing",
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.nanri.aiimage.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 采集执行方路由:哪些模块优先交给本地客户端、多久没人领才由 Linux 兜底。
|
||||
*
|
||||
* <p>2026-10-29 产品口径:外观专利(APPEARANCE_PATENT)与相似ASIN(SIMILAR_ASIN)默认
|
||||
* 「本地采集」。本地优先不等于只认本地——页面推了没人领时,PENDING 超过
|
||||
* {@code linux-fallback-minutes} 就交 Linux 后台认领,否则本地机器全关时任务会无限排队
|
||||
* (PENDING 已不再按时间判死)。
|
||||
*
|
||||
* <p><b>未登记在 {@code local-enabled} 里的模块一律按「非本地」处理</b>,保持它们原有的
|
||||
* 内部认领等待窗口({@code internal-min-pending-minutes})。默认值刻意不是 true:
|
||||
* 开关只对点名的模块生效,新模块不会被悄悄卷进本地优先。
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "aiimage.collect-routing")
|
||||
public class CollectRoutingProperties {
|
||||
|
||||
/** 外观专利模块名(与 biz_file_task.module_type 同口径)。 */
|
||||
public static final String MODULE_APPEARANCE_PATENT = "APPEARANCE_PATENT";
|
||||
|
||||
/** 相似ASIN(货源查询)模块名。 */
|
||||
public static final String MODULE_SIMILAR_ASIN = "SIMILAR_ASIN";
|
||||
|
||||
/** 模块 → 是否本地采集;键为大写模块名。 */
|
||||
private Map<String, Boolean> localEnabled = new LinkedHashMap<>();
|
||||
|
||||
/** 本地采集模块在 PENDING 超过多少分钟后允许 Linux 兜底认领。 */
|
||||
private long linuxFallbackMinutes = 30L;
|
||||
|
||||
public boolean isLocal(String moduleType) {
|
||||
if (moduleType == null || moduleType.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
return Boolean.TRUE.equals(localEnabled.get(moduleType.trim().toUpperCase(Locale.ROOT)));
|
||||
}
|
||||
|
||||
/** 兜底窗口下限 1 分钟:配 0/负数等于关掉本地优先,不允许静默变成「Linux 立刻抢」。 */
|
||||
public long safeLinuxFallbackMinutes() {
|
||||
return Math.max(1L, linuxFallbackMinutes);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties({OssProperties.class, TransientStorageProperties.class, StorageProperties.class, BrandProgressProperties.class, DeleteBrandProgressProperties.class, BrandCheckProperties.class, ZiniaoProperties.class, ModuleCleanupProperties.class, TaskPressureProperties.class, TaskImageCacheCleanupProperties.class, AppearancePatentProperties.class, SimilarAsinProperties.class, ImageVideoProperties.class, InstanceRoutingProperties.class, CapacityPlanProperties.class, UserSecretProperties.class, NotificationProperties.class, DeviceLogOssProperties.class, CollectDataBrandRecheckProperties.class, ClientCredentialProperties.class, CostGuardProperties.class, KeywordShareSyncProperties.class})
|
||||
@EnableConfigurationProperties({OssProperties.class, TransientStorageProperties.class, StorageProperties.class, BrandProgressProperties.class, DeleteBrandProgressProperties.class, BrandCheckProperties.class, ZiniaoProperties.class, ModuleCleanupProperties.class, TaskPressureProperties.class, TaskImageCacheCleanupProperties.class, AppearancePatentProperties.class, SimilarAsinProperties.class, ImageVideoProperties.class, InstanceRoutingProperties.class, CapacityPlanProperties.class, UserSecretProperties.class, NotificationProperties.class, DeviceLogOssProperties.class, CollectDataBrandRecheckProperties.class, ClientCredentialProperties.class, CostGuardProperties.class, KeywordShareSyncProperties.class, CollectRoutingProperties.class})
|
||||
public class PropertiesConfig {
|
||||
}
|
||||
|
||||
+11
@@ -4,6 +4,7 @@ import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.api.PageDefaults;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.dto.AppearancePatentParseRequest;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.dto.AppearancePatentParsedPayloadDto;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.dto.AppearancePatentSubmitResultRequest;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.dto.AppearancePatentTaskBatchRequest;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentDashboardVo;
|
||||
@@ -57,6 +58,16 @@ public class AppearancePatentController {
|
||||
adminAuthSupport.currentDeviceId(httpRequest)));
|
||||
}
|
||||
|
||||
@GetMapping("/tasks/{taskId}/queue-payload")
|
||||
@Operation(summary = "获取外观专利 Python 队列载荷", description = "本地采集模式下,前端取出 groups 后推本机客户端队列;只返回 Python 当前需要的分组,避免前端搬运完整解析大数据。")
|
||||
public ApiResponse<AppearancePatentParsedPayloadDto> queuePayload(
|
||||
@Parameter(description = "外观专利任务 ID", required = true, example = "7004")
|
||||
@PathVariable Long taskId,
|
||||
@Parameter(description = "当前用户 ID", required = true, example = "1")
|
||||
@RequestParam("user_id") Long userId) {
|
||||
return ApiResponse.success(service.queuePayload(taskId, userId));
|
||||
}
|
||||
|
||||
@GetMapping("/dashboard")
|
||||
@Operation(summary = "查询外观专利检测总览", description = "查询当前用户的运行中、成功、失败和已结束任务数量。页面进入时请求一次即可,不需要持续轮询。")
|
||||
public ApiResponse<AppearancePatentDashboardVo> dashboard(
|
||||
|
||||
+42
@@ -113,6 +113,13 @@ public class AppearancePatentTaskService extends AbstractFileTaskPipeline<Appear
|
||||
@org.springframework.beans.factory.annotation.Autowired(required = false)
|
||||
private com.nanri.aiimage.modules.usersecret.service.UserTaskGuardService taskGuard;
|
||||
|
||||
/**
|
||||
* 采集路由开关:字段注入的理由同 {@code taskGuard}——本类构造器被 golden 用例按参数顺序
|
||||
* new 出来,加参数会连带改一批测试。null=未注入(单测)时按「非本地」处理,退回后台语义。
|
||||
*/
|
||||
@org.springframework.beans.factory.annotation.Autowired(required = false)
|
||||
private com.nanri.aiimage.config.CollectRoutingProperties collectRoutingProperties;
|
||||
|
||||
/**
|
||||
* 参数顺序=迁移前 {@code @RequiredArgsConstructor} 的字段声明顺序,一字未动;
|
||||
* 其中五枚(fileTaskMapper/fileResultMapper/taskDistributedLockService/
|
||||
@@ -204,9 +211,44 @@ public class AppearancePatentTaskService extends AbstractFileTaskPipeline<Appear
|
||||
throw new com.nanri.aiimage.common.exception.BusinessException(com.nanri.aiimage.modules
|
||||
.usersecret.service.UserTaskGuardService.PAUSED_MESSAGE);
|
||||
}
|
||||
// 2026-10-29 本地采集开关:开着就恢复「页面推本地客户端」的启动语义;
|
||||
// 关着走原后台语义(记录支持里对 PENDING 明确报「已切换后台自动执行」)。
|
||||
if (collectRoutingProperties != null
|
||||
&& collectRoutingProperties.isLocal(com.nanri.aiimage.config.CollectRoutingProperties.MODULE_APPEARANCE_PATENT)) {
|
||||
activateForLocalClient(taskId, userId);
|
||||
return;
|
||||
}
|
||||
recordSupport().activateTask(taskId, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 本地采集模式的激活:只允许 PENDING→RUNNING 条件更新。
|
||||
*
|
||||
* <p>与客户端兜底拉取 / Linux 内部认领共用同一条原子翻转,谁先翻谁执行,
|
||||
* 页面推送与后台接管不会重复跑同一份任务。
|
||||
*/
|
||||
private void activateForLocalClient(Long taskId, Long userId) {
|
||||
FileTaskEntity task = fileTaskMapper.selectById(taskId);
|
||||
if (task == null || !MODULE_TYPE.equals(task.getModuleType())
|
||||
|| userId == null || !java.util.Objects.equals(userId, task.getUserId())) {
|
||||
throw new com.nanri.aiimage.common.exception.BusinessException("任务不存在");
|
||||
}
|
||||
ensureTaskOwnedByCurrentInstance(task, "activate");
|
||||
int updated = fileTaskMapper.update(null, new LambdaUpdateWrapper<FileTaskEntity>()
|
||||
.eq(FileTaskEntity::getId, taskId)
|
||||
.eq(FileTaskEntity::getStatus, com.nanri.aiimage.common.task.TaskStatuses.FileTask.PENDING)
|
||||
.set(FileTaskEntity::getStatus, STATUS_RUNNING)
|
||||
.set(FileTaskEntity::getUpdatedAt, LocalDateTime.now()));
|
||||
if (updated == 0) {
|
||||
FileTaskEntity latest = fileTaskMapper.selectById(taskId);
|
||||
if (latest != null && STATUS_RUNNING.equals(latest.getStatus())) {
|
||||
throw new com.nanri.aiimage.common.exception.BusinessException("任务已在执行中(可能已由客户端自动接管),无需重复启动");
|
||||
}
|
||||
throw new com.nanri.aiimage.common.exception.BusinessException("任务已结束");
|
||||
}
|
||||
taskCacheService.touchTaskHeartbeat(taskId);
|
||||
}
|
||||
|
||||
public AppearancePatentDashboardVo dashboard(Long userId) {
|
||||
return progressSupport().dashboard(userId);
|
||||
}
|
||||
|
||||
+13
@@ -210,6 +210,13 @@ public class SimilarAsinTaskService implements SimilarAsinPipelineHost {
|
||||
*/
|
||||
private final SimilarAsinImagePrefetchService imagePrefetchService;
|
||||
private final UserApiSecretService userApiSecretService;
|
||||
|
||||
/**
|
||||
* 采集路由开关:字段注入,避免给 {@code @RequiredArgsConstructor} 加参数而牵连一批
|
||||
* 手工 new 本类的测试。null(单测未注入)按「本地」处理,保持 activate 的原有行为。
|
||||
*/
|
||||
@org.springframework.beans.factory.annotation.Autowired(required = false)
|
||||
private com.nanri.aiimage.config.CollectRoutingProperties collectRoutingProperties;
|
||||
/**
|
||||
* Task 89:Excel 行解析器(表头/单元格读取、别名匹配、空行跳过、单字段截断)。
|
||||
* 由 parseAndCreateTask 委托;解析语义与搬移前 parseWorkbook 完全一致。
|
||||
@@ -540,6 +547,12 @@ public class SimilarAsinTaskService implements SimilarAsinPipelineHost {
|
||||
throw new BusinessException("任务不存在");
|
||||
}
|
||||
ownershipSupport().ensureTaskOwnedByCurrentInstance(task, "activate");
|
||||
// 2026-10-29 本地采集开关:关闭时页面不再推本机客户端,任务留 PENDING 等 Linux 后台认领。
|
||||
// 这里把「点启动」明确拒掉,避免旧页面缓存继续推队列造成与后台双跑。
|
||||
if (collectRoutingProperties != null
|
||||
&& !collectRoutingProperties.isLocal(com.nanri.aiimage.config.CollectRoutingProperties.MODULE_SIMILAR_ASIN)) {
|
||||
throw new BusinessException("相似ASIN已切换后台自动执行,无需打开客户端,提交后稍候自动开始");
|
||||
}
|
||||
// 只允许 PENDING→RUNNING(条件更新):与客户端「兜底拉取」的原子认领互斥,
|
||||
// 谁先翻转谁执行,避免页面与客户端重复执行同一任务
|
||||
int updated = fileTaskMapper.update(null, new LambdaUpdateWrapper<FileTaskEntity>()
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.nanri.aiimage.modules.task.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.config.CollectRoutingProperties;
|
||||
import com.nanri.aiimage.modules.task.model.vo.CollectRoutingVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 专利/货源的本地采集开关查询。
|
||||
*
|
||||
* <p>前端据此决定「启动」按钮走哪条链路:本地采集开着就取出队列载荷推本机客户端,
|
||||
* 关着就只建单、等 Linux 后台认领。开关的唯一真源在服务端配置
|
||||
* ({@code aiimage.collect-routing.local-enabled}),前端不自己保存副本。
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/collect-routing")
|
||||
@Tag(name = "采集路由", description = "专利/货源的本地采集开关(前端读取后决定推送本地还是提交后台)")
|
||||
public class CollectRoutingController {
|
||||
|
||||
private final CollectRoutingProperties properties;
|
||||
|
||||
@GetMapping
|
||||
@Operation(summary = "查询本地采集开关", description = "返回外观专利与相似ASIN当前是否走本地采集。只读,无副作用。")
|
||||
public ApiResponse<CollectRoutingVo> routing() {
|
||||
return ApiResponse.success(new CollectRoutingVo(
|
||||
properties.isLocal(CollectRoutingProperties.MODULE_APPEARANCE_PATENT),
|
||||
properties.isLocal(CollectRoutingProperties.MODULE_SIMILAR_ASIN)));
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.nanri.aiimage.modules.task.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "专利/货源的采集执行方开关")
|
||||
public class CollectRoutingVo {
|
||||
|
||||
@Schema(description = "外观专利是否本地采集:true=页面推本地客户端(超时后 Linux 兜底);false=只由 Linux 后台执行")
|
||||
private boolean appearancePatentLocal;
|
||||
|
||||
@Schema(description = "相似ASIN是否本地采集:true=页面推本地客户端(超时后 Linux 兜底);false=只由 Linux 后台执行")
|
||||
private boolean similarAsinLocal;
|
||||
}
|
||||
+50
-7
@@ -2,6 +2,7 @@ package com.nanri.aiimage.modules.task.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.nanri.aiimage.config.CollectRoutingProperties;
|
||||
import com.nanri.aiimage.config.InstanceMetadata;
|
||||
import com.nanri.aiimage.modules.task.mapper.FileTaskMapper;
|
||||
import com.nanri.aiimage.modules.task.model.entity.FileTaskEntity;
|
||||
@@ -25,12 +26,16 @@ import java.util.Map;
|
||||
* 客户端兜底拉取:把"页面没推送成功、长期停在 PENDING"的任务交给在线客户端执行。
|
||||
*
|
||||
* <p>PENDING 表示任务已解析落库、等页面把它推进本机 Python 队列;页面这一环缺失时任务会一直
|
||||
* 停在这里,2 小时后被 {@code StaleTaskRepairService} 标失败。本服务让客户端主动来领:
|
||||
* 停在这里(2026-10-29 起 PENDING 不再按时间判死,只能靠认领通道推进)。本服务让客户端主动来领:
|
||||
* 只挑创建超过 N 分钟仍是 PENDING 的本用户任务,逐条用条件更新认领(PENDING→RUNNING),
|
||||
* 只有把状态翻过来的调用方算领取成功 —— 与页面 activate 天然互斥,不会重复执行。
|
||||
*
|
||||
* <p>开关 {@code aiimage.client-task-pull.enabled} 默认关闭;模块白名单默认只放三个
|
||||
* "执行参数全在服务端"的模块,其余模块实现 {@link ClientTaskPullSpi} 后可逐步加入。
|
||||
* <p>2026-10-29 起按 {@link CollectRoutingProperties} 分两档路由:本地采集模块只允许客户端领;
|
||||
* Linux 内部认领对本地模块要等 {@code linux-fallback-minutes} 的兜底窗口,对非本地模块保持
|
||||
* 原有的 {@code internal-min-pending-minutes}。详见 {@link #pullPendingTasksInternal(List)}。
|
||||
*
|
||||
* <p>开关 {@code aiimage.client-task-pull.enabled} 默认关闭;模块白名单默认只放"执行参数全在服务端"
|
||||
* 的模块,其余模块实现 {@link ClientTaskPullSpi} 后可逐步加入。
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@@ -51,8 +56,10 @@ public class TaskClientPullService {
|
||||
|
||||
private final FileTaskMapper fileTaskMapper;
|
||||
private final InstanceMetadata instanceMetadata;
|
||||
/** moduleType → 模块兜底实现(启动时建索引并校验重复注册)。 */
|
||||
/** 模块 → 模块兜底实现(启动时建索引并校验重复注册)。 */
|
||||
private final Map<String, ClientTaskPullSpi> pullHandlers;
|
||||
/** 专利/货源等模块的本地采集开关与 Linux 兜底窗口。 */
|
||||
private final CollectRoutingProperties collectRoutingProperties;
|
||||
|
||||
@Value("${aiimage.client-task-pull.enabled:false}")
|
||||
private boolean enabled;
|
||||
@@ -80,9 +87,11 @@ public class TaskClientPullService {
|
||||
|
||||
public TaskClientPullService(FileTaskMapper fileTaskMapper,
|
||||
InstanceMetadata instanceMetadata,
|
||||
CollectRoutingProperties collectRoutingProperties,
|
||||
List<ClientTaskPullSpi> handlers) {
|
||||
this.fileTaskMapper = fileTaskMapper;
|
||||
this.instanceMetadata = instanceMetadata;
|
||||
this.collectRoutingProperties = collectRoutingProperties;
|
||||
Map<String, ClientTaskPullSpi> index = new LinkedHashMap<>();
|
||||
for (ClientTaskPullSpi handler : handlers == null ? List.<ClientTaskPullSpi>of() : handlers) {
|
||||
String moduleType = handler.moduleType();
|
||||
@@ -109,8 +118,10 @@ public class TaskClientPullService {
|
||||
*/
|
||||
@PostConstruct
|
||||
public void logEffectiveConfig() {
|
||||
log.info("[client-task-pull] 生效配置 enabled={} internalEnabled={} internalMinPendingMinutes={} moduleTypes={} minPendingMinutes={} limit={} handlers={}",
|
||||
enabled, internalEnabled, internalMinPendingMinutes, moduleTypes, minPendingMinutes, Math.max(1, Math.min(limit, MAX_LIMIT)), pullHandlers.keySet());
|
||||
log.info("[client-task-pull] 生效配置 enabled={} internalEnabled={} internalMinPendingMinutes={} moduleTypes={} minPendingMinutes={} limit={} handlers={} localEnabled={} linuxFallbackMinutes={}",
|
||||
enabled, internalEnabled, internalMinPendingMinutes, moduleTypes, minPendingMinutes,
|
||||
Math.max(1, Math.min(limit, MAX_LIMIT)), pullHandlers.keySet(),
|
||||
collectRoutingProperties.getLocalEnabled(), collectRoutingProperties.safeLinuxFallbackMinutes());
|
||||
}
|
||||
|
||||
/** 拉取并认领该用户"长期未被领取"的任务,按创建时间升序返回,最多 limit 条。 */
|
||||
@@ -126,6 +137,13 @@ public class TaskClientPullService {
|
||||
log.warn("[client-task-pull] 模块白名单为空,本次不拉取 userId={}", userId);
|
||||
return List.of();
|
||||
}
|
||||
// 只拉本地采集模块:关掉本地开关的模块只认 Linux 后台,客户端拿到会算抢跑
|
||||
types = types.stream().filter(collectRoutingProperties::isLocal).toList();
|
||||
if (types.isEmpty()) {
|
||||
log.info("[client-task-pull] 白名单模块均已切换 Linux 后台执行,客户端不拉取 userId={} moduleTypes={}",
|
||||
userId, moduleTypes);
|
||||
return List.of();
|
||||
}
|
||||
long startedAt = System.currentTimeMillis();
|
||||
LocalDateTime cutoff = LocalDateTime.now(DB_ZONE).minusMinutes(Math.max(1L, minPendingMinutes));
|
||||
int safeLimit = Math.max(1, Math.min(limit, MAX_LIMIT));
|
||||
@@ -149,6 +167,11 @@ public class TaskClientPullService {
|
||||
* <p>与页面 activate / 客户端兜底拉取共用同一条 PENDING→RUNNING 原子认领,天然互斥不重复执行。
|
||||
* 独立开关 {@code aiimage.client-task-pull.internal-enabled},与客户端开关解耦:
|
||||
* 客户端侧未升级/未开启时也能单独让服务端 worker 上线。
|
||||
*
|
||||
* <p><b>2026-10-29 本地优先</b>:本地采集模块({@code aiimage.collect-routing.local-enabled})
|
||||
* 的任务要让位给本地客户端——PENDING 超过 {@code linux-fallback-minutes} 还没被本地领取,
|
||||
* 才允许这里接管;非本地模块保持 {@code internal-min-pending-minutes} 的原窗口。
|
||||
* 没有这层过滤,页面刚把任务推给客户端,Linux 就会在 2 分钟后抢走并双跑。
|
||||
*/
|
||||
public List<TaskClientPullVo> pullPendingTasksInternal(List<String> moduleTypes) {
|
||||
if (!internalEnabled) {
|
||||
@@ -161,7 +184,12 @@ public class TaskClientPullService {
|
||||
return List.of();
|
||||
}
|
||||
long startedAt = System.currentTimeMillis();
|
||||
LocalDateTime cutoff = LocalDateTime.now(DB_ZONE).minusMinutes(Math.max(1L, internalMinPendingMinutes));
|
||||
LocalDateTime now = LocalDateTime.now(DB_ZONE);
|
||||
LocalDateTime cutoff = now.minusMinutes(Math.max(1L, internalMinPendingMinutes));
|
||||
// 兜底窗口不得短于基础等待窗口:配小了也没法越过「建完就能删」的余地
|
||||
long localFallbackMinutes = Math.max(collectRoutingProperties.safeLinuxFallbackMinutes(),
|
||||
Math.max(1L, internalMinPendingMinutes));
|
||||
LocalDateTime localCutoff = now.minusMinutes(localFallbackMinutes);
|
||||
int safeLimit = Math.max(1, Math.min(limit, MAX_LIMIT));
|
||||
List<FileTaskEntity> candidates = fileTaskMapper.selectList(new LambdaQueryWrapper<FileTaskEntity>()
|
||||
.select(FileTaskEntity::getId, FileTaskEntity::getModuleType, FileTaskEntity::getCreatedAt)
|
||||
@@ -170,6 +198,21 @@ public class TaskClientPullService {
|
||||
.lt(FileTaskEntity::getCreatedAt, cutoff)
|
||||
.orderByAsc(FileTaskEntity::getCreatedAt)
|
||||
.last("limit " + safeLimit));
|
||||
if (!candidates.isEmpty()) {
|
||||
int before = candidates.size();
|
||||
candidates = candidates.stream()
|
||||
.filter(task -> !collectRoutingProperties.isLocal(task.getModuleType())
|
||||
|| task.getCreatedAt() == null
|
||||
|| !task.getCreatedAt().isAfter(localCutoff))
|
||||
.toList();
|
||||
if (candidates.size() < before) {
|
||||
log.info("[client-task-pull] 内部认领让位本地:本轮跳过 {} 条本地采集模块的排队任务(兜底窗口 {} 分钟)",
|
||||
before - candidates.size(), localFallbackMinutes);
|
||||
}
|
||||
}
|
||||
if (candidates.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
List<TaskClientPullVo> claimed = claimCandidates(candidates, "内部认领");
|
||||
log.info("[client-task-pull] 内部认领完成 types={} 候选={} 认领={} 耗时={}ms",
|
||||
types, candidates.size(), claimed.size(), System.currentTimeMillis() - startedAt);
|
||||
|
||||
@@ -17,6 +17,12 @@ AIIMAGE_COST_GUARD_LLM_WINDOW_TOKENS_THRESHOLD=600000
|
||||
AIIMAGE_COST_GUARD_PLATFORM_PROXY_DAILY_THRESHOLD=2000
|
||||
AIIMAGE_COST_GUARD_SHARED_ACCOUNTS_THRESHOLD=3
|
||||
|
||||
# 采集执行方路由:专利/货源默认本地采集;关掉则只由 Linux 后台执行。
|
||||
# 本地采集的任务 PENDING 超过该分钟数还没被客户端领走,才允许 Linux 兜底。
|
||||
AIIMAGE_COLLECT_LOCAL_APPEARANCE_PATENT=true
|
||||
AIIMAGE_COLLECT_LOCAL_SIMILAR_ASIN=true
|
||||
AIIMAGE_COLLECT_LINUX_FALLBACK_MINUTES=30
|
||||
|
||||
AIIMAGE_DB_URL=jdbc:mysql://127.0.0.1:3306/aiimage?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false
|
||||
AIIMAGE_DB_USERNAME=change-me
|
||||
AIIMAGE_DB_PASSWORD=change-me
|
||||
|
||||
@@ -372,6 +372,16 @@ aiimage:
|
||||
heartbeat-interval-ms: ${AIIMAGE_RESULT_FILE_JOB_HEARTBEAT_INTERVAL_MS:60000}
|
||||
batch-size: ${AIIMAGE_RESULT_FILE_JOB_BATCH_SIZE:20}
|
||||
max-inflight-dispatch: ${AIIMAGE_RESULT_FILE_JOB_MAX_INFLIGHT_DISPATCH:64}
|
||||
# 采集执行方路由(2026-10-29):外观专利与相似ASIN默认「本地采集」,页面推本机客户端;
|
||||
# 推了超过 linux-fallback-minutes 还没被客户端领走,才允许 Linux 后台兜底认领
|
||||
# (PENDING 已不再按时间判死,没有兜底窗口的话本地机全关时任务会一直排队)。
|
||||
# 关掉某模块=该模块只由 Linux 后台执行,页面不再推送。未登记的模块按「非本地」处理,
|
||||
# 保持内部认领原有的 internal-min-pending-minutes,不被卷进本地优先。
|
||||
collect-routing:
|
||||
local-enabled:
|
||||
APPEARANCE_PATENT: ${AIIMAGE_COLLECT_LOCAL_APPEARANCE_PATENT:true}
|
||||
SIMILAR_ASIN: ${AIIMAGE_COLLECT_LOCAL_SIMILAR_ASIN:true}
|
||||
linux-fallback-minutes: ${AIIMAGE_COLLECT_LINUX_FALLBACK_MINUTES:30}
|
||||
# 客户端兜底拉取:页面没推送成功(只解析没点启动 / 推送前关页面 / 纯浏览器打开)、
|
||||
# 长期停在 PENDING 的任务由在线客户端领走执行。2026-10-29 起 PENDING 不再按 2 小时判死
|
||||
# (排队中的任务一直排队等认领),本开关是排队任务的唯一出路,不再是"判死前的抢救"。
|
||||
|
||||
Reference in New Issue
Block a user