task-76: JSON owner 查询迁移到显式列并补充任务/状态复合索引
This commit is contained in:
+2
@@ -17,6 +17,8 @@ public class TaskFileJobEntity {
|
||||
private String moduleType;
|
||||
private Long resultId;
|
||||
private String scopeKey;
|
||||
/** 从 scope_key 提取的显式 owner(task:1:owner:instance-a → instance-a),支持等值索引查询。 */
|
||||
private String owner;
|
||||
private String jobType;
|
||||
private String status;
|
||||
private Integer retryCount;
|
||||
|
||||
+21
-10
@@ -40,6 +40,7 @@ public class TaskFileJobService {
|
||||
entity.setModuleType(moduleType);
|
||||
entity.setResultId(resultId);
|
||||
entity.setScopeKey(scopeKey);
|
||||
entity.setOwner(ownerFromScopeKey(scopeKey));
|
||||
entity.setJobType(JOB_TYPE_ASSEMBLE_RESULT);
|
||||
entity.setStatus("PENDING");
|
||||
entity.setRetryCount(0);
|
||||
@@ -68,6 +69,7 @@ public class TaskFileJobService {
|
||||
taskFileJobMapper.update(null, new LambdaUpdateWrapper<TaskFileJobEntity>()
|
||||
.eq(TaskFileJobEntity::getId, existing.getId())
|
||||
.set(TaskFileJobEntity::getScopeKey, scopeKey)
|
||||
.set(TaskFileJobEntity::getOwner, ownerFromScopeKey(scopeKey))
|
||||
.set(TaskFileJobEntity::getStatus, "PENDING")
|
||||
.set(TaskFileJobEntity::getErrorMessage, null)
|
||||
.set(TaskFileJobEntity::getUpdatedAt, now)
|
||||
@@ -103,14 +105,13 @@ public class TaskFileJobService {
|
||||
if (normalizedOwner.isBlank()) {
|
||||
return claimRunnableJobs(limit);
|
||||
}
|
||||
String ownerMarker = ":owner:" + normalizedOwner;
|
||||
int safeLimit = Math.max(1, Math.min(limit, 100));
|
||||
|
||||
List<TaskFileJobEntity> ownerJobs = taskFileJobMapper.selectList(new LambdaQueryWrapper<TaskFileJobEntity>()
|
||||
.in(TaskFileJobEntity::getStatus, List.of("PENDING", "FAILED"))
|
||||
.lt(TaskFileJobEntity::getRetryCount, MAX_RETRY_COUNT)
|
||||
.in(TaskFileJobEntity::getModuleType, List.of("APPEARANCE_PATENT", "SIMILAR_ASIN", "PUBLISH", "SHOP_DATA_CRAWL"))
|
||||
.like(TaskFileJobEntity::getScopeKey, ownerMarker)
|
||||
.eq(TaskFileJobEntity::getOwner, normalizedOwner)
|
||||
.orderByAsc(TaskFileJobEntity::getUpdatedAt)
|
||||
.last("limit " + safeLimit));
|
||||
|
||||
@@ -122,9 +123,7 @@ public class TaskFileJobService {
|
||||
.and(wrapper -> wrapper
|
||||
.notIn(TaskFileJobEntity::getModuleType, List.of("APPEARANCE_PATENT", "SIMILAR_ASIN", "PUBLISH", "SHOP_DATA_CRAWL"))
|
||||
.or()
|
||||
.isNull(TaskFileJobEntity::getScopeKey)
|
||||
.or()
|
||||
.notLike(TaskFileJobEntity::getScopeKey, ":owner:"))
|
||||
.isNull(TaskFileJobEntity::getOwner))
|
||||
.orderByAsc(TaskFileJobEntity::getUpdatedAt)
|
||||
.last("limit " + (safeLimit - ownerJobs.size()));
|
||||
candidates.addAll(taskFileJobMapper.selectList(genericWrapper));
|
||||
@@ -157,14 +156,13 @@ public class TaskFileJobService {
|
||||
if (normalizedOwner.isBlank()) {
|
||||
return listRunnableJobs(limit);
|
||||
}
|
||||
String ownerMarker = ":owner:" + normalizedOwner;
|
||||
int safeLimit = Math.max(1, Math.min(limit, 100));
|
||||
|
||||
List<TaskFileJobEntity> ownerJobs = taskFileJobMapper.selectList(new LambdaQueryWrapper<TaskFileJobEntity>()
|
||||
.in(TaskFileJobEntity::getStatus, List.of("PENDING", "FAILED"))
|
||||
.lt(TaskFileJobEntity::getRetryCount, MAX_RETRY_COUNT)
|
||||
.in(TaskFileJobEntity::getModuleType, List.of("APPEARANCE_PATENT", "SIMILAR_ASIN", "PUBLISH", "SHOP_DATA_CRAWL"))
|
||||
.like(TaskFileJobEntity::getScopeKey, ownerMarker)
|
||||
.eq(TaskFileJobEntity::getOwner, normalizedOwner)
|
||||
.orderByAsc(TaskFileJobEntity::getUpdatedAt)
|
||||
.last("limit " + safeLimit));
|
||||
if (ownerJobs.size() >= safeLimit) {
|
||||
@@ -178,9 +176,7 @@ public class TaskFileJobService {
|
||||
.and(wrapper -> wrapper
|
||||
.notIn(TaskFileJobEntity::getModuleType, List.of("APPEARANCE_PATENT", "SIMILAR_ASIN", "PUBLISH", "SHOP_DATA_CRAWL"))
|
||||
.or()
|
||||
.isNull(TaskFileJobEntity::getScopeKey)
|
||||
.or()
|
||||
.notLike(TaskFileJobEntity::getScopeKey, ":owner:"))
|
||||
.isNull(TaskFileJobEntity::getOwner))
|
||||
.orderByAsc(TaskFileJobEntity::getUpdatedAt)
|
||||
.last("limit " + (safeLimit - jobs.size()));
|
||||
jobs.addAll(taskFileJobMapper.selectList(genericWrapper));
|
||||
@@ -586,6 +582,21 @@ public class TaskFileJobService {
|
||||
.eq(TaskFileJobEntity::getResultId, resultId));
|
||||
}
|
||||
|
||||
private static final String OWNER_MARKER = ":owner:";
|
||||
|
||||
/** 从 scope_key(task:1:owner:instance-a)提取 owner;无标记或空白返回 null。 */
|
||||
static String ownerFromScopeKey(String scopeKey) {
|
||||
if (scopeKey == null || scopeKey.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
int index = scopeKey.lastIndexOf(OWNER_MARKER);
|
||||
if (index < 0) {
|
||||
return null;
|
||||
}
|
||||
String owner = scopeKey.substring(index + OWNER_MARKER.length()).trim();
|
||||
return owner.isBlank() ? null : owner;
|
||||
}
|
||||
|
||||
private TaskFileJobEntity findJob(Long taskId, String moduleType, Long resultId, String jobType) {
|
||||
if (taskId == null || moduleType == null || moduleType.isBlank() || resultId == null || jobType == null || jobType.isBlank()) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user