fix(backlog): 品牌出口统一、join 截止与进行中任务补回
- BrandLabel 出口守卫扩到全仓 entity.setBrand,撞款/去重/品牌库统一清洗 - FutureDeadline 替换五处无界 join,回传口锁等待降为 1s - 采集/跟价/外观专利 history 补回窗口外进行中与续跑任务 - 工作台客户端版本强制单调;catch 棘轮按新增出口逐处记名
This commit is contained in:
+18
-3
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.nanri.aiimage.common.retry.LlmKeyGate;
|
||||
import com.nanri.aiimage.common.retry.LlmRetryBackoff;
|
||||
import com.nanri.aiimage.common.retry.UnreachableCooldown;
|
||||
import com.nanri.aiimage.common.support.FutureDeadline;
|
||||
import com.nanri.aiimage.config.AppearancePatentProperties;
|
||||
import com.nanri.aiimage.config.HttpClientPool;
|
||||
import com.nanri.aiimage.metrics.ExternalCallMetricsRecorder;
|
||||
@@ -32,9 +33,12 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -376,6 +380,13 @@ public class AppearancePatentLlmClient {
|
||||
return chunks;
|
||||
}
|
||||
|
||||
/** 单批等待上限:按一次读超时 × 重试次数再留一倍余量,封顶 2 小时。 */
|
||||
private long futureDeadlineMillis() {
|
||||
long perAttempt = Math.max(1_000L, properties.getLlmReadTimeoutMillis());
|
||||
long total = perAttempt * (Math.max(1, properties.getLlmRetryTimes()) + 1L);
|
||||
return Math.min(TimeUnit.HOURS.toMillis(2), Math.max(TimeUnit.MINUTES.toMillis(5), total * 2));
|
||||
}
|
||||
|
||||
private <T> List<BatchOutcome<T>> runBatches(List<List<Integer>> chunks, BatchInvoker<T> invoker) {
|
||||
Semaphore concurrency = new Semaphore(Math.max(1, properties.getLlmRowConcurrency()));
|
||||
ExecutorService executor = rowExecutor();
|
||||
@@ -401,12 +412,16 @@ public class AppearancePatentLlmClient {
|
||||
List<BatchOutcome<T>> outcomes = new ArrayList<>(chunks.size());
|
||||
for (int i = 0; i < futures.size(); i++) {
|
||||
try {
|
||||
outcomes.add(futures.get(i).join());
|
||||
} catch (Exception ex) {
|
||||
// 调度层炸了(invoker 本该自己 catch 干净):按传输失败收口,宁可整批记失败也不逐行放大
|
||||
outcomes.add(FutureDeadline.await(futures.get(i), futureDeadlineMillis(), "外观专利 LLM 批次"));
|
||||
} catch (TimeoutException | ExecutionException ex) {
|
||||
// 调度层炸了或单批超过等待上限(invoker 本该自己 catch 干净):按传输失败收口
|
||||
log.warn("[appearance-patent] llm batch crashed rows={} err={}",
|
||||
chunks.get(i).size(), failureMessage(ex));
|
||||
outcomes.add(new BatchOutcome<T>(Map.of(), failureMessage(ex), false));
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
log.warn("[appearance-patent] llm batch wait interrupted rows={}", chunks.get(i).size());
|
||||
outcomes.add(new BatchOutcome<T>(Map.of(), "LLM 批次等待被中断", false));
|
||||
}
|
||||
}
|
||||
return outcomes;
|
||||
|
||||
+12
@@ -63,6 +63,18 @@ public class AppearancePatentHistoryAssembler {
|
||||
return vo;
|
||||
}
|
||||
|
||||
/** 结果行不在返回窗口里的在跑/续跑任务:只带前端渲染当前任务所需字段。 */
|
||||
public AppearancePatentHistoryItemVo buildActiveItem(FileTaskEntity task) {
|
||||
AppearancePatentHistoryItemVo vo = new AppearancePatentHistoryItemVo();
|
||||
vo.setTaskId(task.getId());
|
||||
vo.setTaskStatus(task.getStatus());
|
||||
vo.setSuccess(false);
|
||||
vo.setCreatedAt(fmt(task.getCreatedAt()));
|
||||
vo.setStartedAt(fmt(task.getCreatedAt()));
|
||||
vo.setFinishedAt(fmt(task.getFinishedAt()));
|
||||
return vo;
|
||||
}
|
||||
|
||||
public int historyPriority(FileResultEntity row, FileTaskEntity task, TaskFileJobEntity job) {
|
||||
String taskStatus = task == null ? null : task.getStatus();
|
||||
if (STATUS_PENDING.equals(taskStatus) || STATUS_RUNNING.equals(taskStatus) || isHistoryFileBuilding(row, taskStatus, job)) {
|
||||
|
||||
+37
@@ -125,9 +125,46 @@ public class AppearancePatentProgressSupport {
|
||||
FileTaskEntity task = taskMap.get(row.getTaskId());
|
||||
vo.getItems().add(toHistoryItem(row, task, jobMap.get(row.getId())));
|
||||
}
|
||||
prependActiveTasksOutsideWindow(vo, userId, taskIds);
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 结果行被 top-N 窗口挤出后,仍在执行/续跑排队的任务会从列表彻底消失
|
||||
* (页面重载即无兜底)。这里按任务头补回最前面;已有结果行的任务不重复补。
|
||||
*/
|
||||
private void prependActiveTasksOutsideWindow(AppearancePatentHistoryVo vo, Long userId, List<Long> coveredTaskIds) {
|
||||
List<FileTaskEntity> activeTasks = fileTaskMapper.selectList(new LambdaQueryWrapper<FileTaskEntity>()
|
||||
.select(FileTaskEntity::getId,
|
||||
FileTaskEntity::getStatus,
|
||||
FileTaskEntity::getResumeOfTaskId,
|
||||
FileTaskEntity::getCreatedAt,
|
||||
FileTaskEntity::getFinishedAt)
|
||||
.eq(FileTaskEntity::getModuleType, moduleType)
|
||||
.eq(FileTaskEntity::getUserId, userId)
|
||||
.in(FileTaskEntity::getStatus, TaskStatuses.FileTask.ACTIVE_ORDERED)
|
||||
.orderByDesc(FileTaskEntity::getCreatedAt)
|
||||
.last("limit 50"));
|
||||
if (activeTasks == null || activeTasks.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
AppearancePatentHistoryAssembler assembler = historyAssembler();
|
||||
List<AppearancePatentHistoryItemVo> activeItems = new ArrayList<>();
|
||||
for (FileTaskEntity task : activeTasks) {
|
||||
if (task == null || task.getId() == null || coveredTaskIds.contains(task.getId())) {
|
||||
continue;
|
||||
}
|
||||
// 普通 PENDING 是未启动的解析预览,不进列表;续跑克隆件必须留(与相似 ASIN 同口径)
|
||||
if (TaskStatuses.FileTask.PENDING.equals(task.getStatus()) && task.getResumeOfTaskId() == null) {
|
||||
continue;
|
||||
}
|
||||
activeItems.add(assembler.buildActiveItem(task));
|
||||
}
|
||||
if (!activeItems.isEmpty()) {
|
||||
vo.getItems().addAll(0, activeItems);
|
||||
}
|
||||
}
|
||||
|
||||
public AppearancePatentTaskBatchVo progressBatch(List<Long> taskIds) {
|
||||
AppearancePatentTaskBatchVo vo = new AppearancePatentTaskBatchVo();
|
||||
List<Long> normalizedIds = taskIds == null ? List.of() : taskIds.stream()
|
||||
|
||||
Reference in New Issue
Block a user