更新这个货源
This commit is contained in:
+18
@@ -223,9 +223,12 @@ public class TaskFileJobService {
|
||||
if (jobId == null || jobId <= 0) {
|
||||
return false;
|
||||
}
|
||||
// 仅在状态从非 PENDING 切换到 PENDING 时更新并发布事件,
|
||||
// 避免对已在排队中的 job 重复触发 dispatch(同一 jobId 在多个 dispatch 线程并发处理)。
|
||||
int updated = taskFileJobMapper.update(null, new LambdaUpdateWrapper<TaskFileJobEntity>()
|
||||
.eq(TaskFileJobEntity::getId, jobId)
|
||||
.ne(TaskFileJobEntity::getStatus, "SUCCESS")
|
||||
.ne(TaskFileJobEntity::getStatus, "PENDING")
|
||||
.set(TaskFileJobEntity::getStatus, "PENDING")
|
||||
.set(TaskFileJobEntity::getErrorMessage, message)
|
||||
.set(TaskFileJobEntity::getUpdatedAt, LocalDateTime.now())
|
||||
@@ -267,6 +270,21 @@ public class TaskFileJobService {
|
||||
.set(TaskFileJobEntity::getFinishedAt, retryCount >= 5 ? LocalDateTime.now() : null));
|
||||
}
|
||||
|
||||
/**
|
||||
* 终态失败:把 retryCount 直接拉满到上限,让 listRunnableJobs 不再扫到该 job。
|
||||
* 适用于 task/result 已经不存在等无法通过重试恢复的场景。
|
||||
*/
|
||||
public void markFailedPermanent(TaskFileJobEntity job, String message) {
|
||||
taskFileJobMapper.update(null, new LambdaUpdateWrapper<TaskFileJobEntity>()
|
||||
.eq(TaskFileJobEntity::getId, job.getId())
|
||||
.ne(TaskFileJobEntity::getStatus, "SUCCESS")
|
||||
.set(TaskFileJobEntity::getStatus, "FAILED")
|
||||
.set(TaskFileJobEntity::getRetryCount, 5)
|
||||
.set(TaskFileJobEntity::getErrorMessage, message == null ? "结果文件生成失败" : message)
|
||||
.set(TaskFileJobEntity::getUpdatedAt, LocalDateTime.now())
|
||||
.set(TaskFileJobEntity::getFinishedAt, LocalDateTime.now()));
|
||||
}
|
||||
|
||||
public TaskFileJobEntity findAssembleJob(Long taskId, String moduleType, Long resultId) {
|
||||
return findJob(taskId, moduleType, resultId, JOB_TYPE_ASSEMBLE_RESULT);
|
||||
}
|
||||
|
||||
+22
@@ -1,5 +1,6 @@
|
||||
package com.nanri.aiimage.modules.task.service;
|
||||
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.modules.appearancepatent.service.AppearancePatentTaskService;
|
||||
import com.nanri.aiimage.config.InstanceMetadata;
|
||||
import com.nanri.aiimage.modules.brand.service.BrandTaskService;
|
||||
@@ -162,12 +163,33 @@ public class TaskResultFileJobWorker {
|
||||
return;
|
||||
}
|
||||
String message = ex.getMessage() == null ? "结果文件生成失败" : ex.getMessage();
|
||||
// 孤儿 job:fileTask/fileResult 已被删除却残留 task_file_job 行,重试 5 次也救不回来,
|
||||
// 直接拉满 retryCount 让 worker 跳过,避免每 15 秒刷一次 task not found 警告日志。
|
||||
if (isOrphanJobFailure(ex, message)) {
|
||||
log.warn("[task-file-job] process aborted because owning task/result no longer exists jobId={} taskId={} moduleType={} resultId={} msg={}",
|
||||
job.getId(), job.getTaskId(), job.getModuleType(), job.getResultId(), message);
|
||||
taskFileJobService.markFailedPermanent(job, message);
|
||||
return;
|
||||
}
|
||||
log.warn("[task-file-job] process failed jobId={} taskId={} moduleType={} resultId={} msg={}",
|
||||
job.getId(), job.getTaskId(), job.getModuleType(), job.getResultId(), message);
|
||||
taskFileJobService.markFailed(job, message);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isOrphanJobFailure(Exception ex, String message) {
|
||||
if (!(ex instanceof BusinessException)) {
|
||||
return false;
|
||||
}
|
||||
if (message == null) {
|
||||
return false;
|
||||
}
|
||||
return message.contains("task not found")
|
||||
|| message.contains("result record not found")
|
||||
|| message.contains("任务不存在")
|
||||
|| message.contains("记录不存在");
|
||||
}
|
||||
|
||||
private String resolveResultFileUrl(TaskFileJobEntity job) {
|
||||
if ("BRAND".equals(job.getModuleType())) {
|
||||
return brandTaskService.resolveResultObjectKey(job.getTaskId());
|
||||
|
||||
Reference in New Issue
Block a user