后台更新 服务优化
This commit is contained in:
+3
@@ -9,6 +9,9 @@ import lombok.Data;
|
||||
@Schema(description = "任务心跳请求")
|
||||
public class TaskHeartbeatRequest {
|
||||
|
||||
@Schema(description = "可选的任务模块类型;传入后可避免跨任务表探测", example = "SHOP_DATA_CRAWL")
|
||||
private String moduleType;
|
||||
|
||||
@Schema(description = "可选的任务阶段标识", example = "crawling")
|
||||
private String phase;
|
||||
|
||||
|
||||
+23
-9
@@ -78,15 +78,15 @@ public class TaskHeartbeatService {
|
||||
return TaskHeartbeatVo.notAlive(null, null, "invalid taskId");
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<FileTaskEntity> fileQuery = new LambdaQueryWrapper<FileTaskEntity>()
|
||||
.eq(FileTaskEntity::getId, taskId)
|
||||
.last("limit 1");
|
||||
FileTaskEntity fileTask = fileTaskMapper.selectOne(fileQuery);
|
||||
|
||||
LambdaQueryWrapper<BrandCrawlTaskEntity> brandQuery = new LambdaQueryWrapper<BrandCrawlTaskEntity>()
|
||||
.eq(BrandCrawlTaskEntity::getId, taskId)
|
||||
.last("limit 1");
|
||||
BrandCrawlTaskEntity brandTask = brandCrawlTaskMapper.selectOne(brandQuery);
|
||||
String requestedModuleType = request == null || request.getModuleType() == null
|
||||
? null
|
||||
: request.getModuleType().trim();
|
||||
FileTaskEntity fileTask = MODULE_BRAND.equalsIgnoreCase(requestedModuleType)
|
||||
? null
|
||||
: selectFileTask(taskId);
|
||||
BrandCrawlTaskEntity brandTask = MODULE_SHOP_DATA_CRAWL.equalsIgnoreCase(requestedModuleType)
|
||||
? null
|
||||
: selectBrandTask(taskId);
|
||||
|
||||
TaskHeartbeatVo fileResult = touchFileTaskIfRunning(fileTask, request);
|
||||
TaskHeartbeatVo brandResult = touchBrandTaskIfRunning(brandTask, request);
|
||||
@@ -110,6 +110,20 @@ public class TaskHeartbeatService {
|
||||
return TaskHeartbeatVo.notAlive(null, null, "task not found");
|
||||
}
|
||||
|
||||
private FileTaskEntity selectFileTask(Long taskId) {
|
||||
LambdaQueryWrapper<FileTaskEntity> fileQuery = new LambdaQueryWrapper<FileTaskEntity>()
|
||||
.eq(FileTaskEntity::getId, taskId)
|
||||
.last("limit 1");
|
||||
return fileTaskMapper.selectOne(fileQuery);
|
||||
}
|
||||
|
||||
private BrandCrawlTaskEntity selectBrandTask(Long taskId) {
|
||||
LambdaQueryWrapper<BrandCrawlTaskEntity> brandQuery = new LambdaQueryWrapper<BrandCrawlTaskEntity>()
|
||||
.eq(BrandCrawlTaskEntity::getId, taskId)
|
||||
.last("limit 1");
|
||||
return brandCrawlTaskMapper.selectOne(brandQuery);
|
||||
}
|
||||
|
||||
private TaskHeartbeatVo touchFileTaskIfRunning(FileTaskEntity task, TaskHeartbeatRequest request) {
|
||||
if (task == null) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user