feat(cost-guard): 代理/LLM 损耗监控与账号级任务暂停

- 每分钟扫描用量增量/日累计,异常置暂停闸并推站内通知
- 品牌补测、跟价派发、外观激活、品牌检测与两个 LLM 客户端统一接闸
- 同一代理/LLM 密钥被 3 个以上账号共用时给出用户提示
- 品牌检测出口拒绝批级熔断;LLM 同 key 共享并发/间隔/429 惩罚
- V170 新增 biz_user_task_guard
This commit is contained in:
2026-10-24 10:50:20 +08:00
parent 052f2bd4a5
commit 9c4905c94e
32 changed files with 1625 additions and 5 deletions
@@ -59,6 +59,10 @@ public class CollectDataBrandRecheckScheduler {
private final TaskFileJobService taskFileJobService;
private final DistributedJobLockService distributedJobLockService;
/** 损耗闸:字段注入避免改动手工构造的调度器用例;null=未启用(单测)。 */
@org.springframework.beans.factory.annotation.Autowired(required = false)
private com.nanri.aiimage.modules.usersecret.service.UserTaskGuardService taskGuard;
@Scheduled(fixedDelayString = "${aiimage.collect-data.brand-recheck.scan-interval-ms:300000}",
initialDelayString = "${aiimage.collect-data.brand-recheck.scan-initial-delay-ms:120000}")
public void scan() {
@@ -124,6 +128,13 @@ public class CollectDataBrandRecheckScheduler {
}
return new GroupRound(0, 0);
}
if (taskGuard != null && taskGuard.isPaused(task.getUserId())) {
// 暂停不消耗尝试次数:用户排查完点继续后,这批条目应按原退避节奏重新到期
recheckService.postponeWithoutAttempt(entries, properties.getIntervalBaseMinutes());
log.info("[brand-recheck] 账号任务已暂停,整组顺延 taskId={} userId={} 条目={}",
taskId, task.getUserId(), entries.size());
return new GroupRound(0, 0);
}
if (!STATUS_SUCCESS.equals(task.getStatus()) && !STATUS_FAILED.equals(task.getStatus())) {
// 任务仍在跑:补测只做终态之后的兜底,顺延不计数(避免与分片重提竞态)
recheckService.postponeWithoutAttempt(entries, properties.getFirstDelayMinutes());