feat:优化

This commit is contained in:
2025-11-22 01:42:20 +08:00
parent a3cc6c6db0
commit 161d9568a9
4 changed files with 240 additions and 67 deletions

View File

@@ -129,6 +129,8 @@ public class LatentsyncClient {
.addQueryParameter("request_id", requestId)
.build();
log.info("[Latentsync][get result] requestId={}, url={}", requestId, url);
Request httpRequest = new Request.Builder()
.url(url)
.addHeader("Authorization", "Bearer " + properties.getApiKey())
@@ -138,6 +140,7 @@ public class LatentsyncClient {
try {
return executeRequest(httpRequest, "get result", requestId);
} catch (ServiceException ex) {
log.error("[Latentsync][get result failed] requestId={}, message={}", requestId, ex.getMessage());
throw ex;
} catch (Exception ex) {
log.error("[Latentsync][get result exception]", ex);
@@ -196,7 +199,16 @@ public class LatentsyncClient {
private ServiceException buildException(String body) {
try {
JsonNode root = objectMapper.readTree(body);
String message = root.path("message").asText(body);
// 尝试读取 message 字段(标准错误格式)
String message = root.path("message").asText("");
// 如果没有 message尝试读取 detail 字段302AI 的错误格式)
if (StrUtil.isBlank(message)) {
message = root.path("detail").asText("");
}
// 如果都没有,使用整个响应体
if (StrUtil.isBlank(message)) {
message = body;
}
return exception0(LATENTSYNC_SUBMIT_FAILED.getCode(), message);
} catch (Exception ignored) {
return exception0(LATENTSYNC_SUBMIT_FAILED.getCode(), body);

View File

@@ -476,7 +476,7 @@ public class DigitalHumanTaskServiceImpl implements DigitalHumanTaskService {
log.info("[syncWithLatentsync][任务({})提交成功requestId={}]", task.getId(), requestId);
// 轮询等待任务完成
int maxAttempts = 60; // 最多轮询60次
int maxAttempts = 90; // 最多轮询90次15分钟
int attempt = 0;
while (attempt < maxAttempts) {
attempt++;
@@ -485,8 +485,10 @@ public class DigitalHumanTaskServiceImpl implements DigitalHumanTaskService {
AppTikLatentsyncResultRespVO result = latentsyncService.getTaskResult(requestId);
String status = result.getStatus();
log.info("[syncWithLatentsync][任务({})轮询结果: 第{}次, status={}]", task.getId(), attempt, status);
log.info("[syncWithLatentsync][任务({})轮询结果: 第{}次, status={}]",
task.getId(), attempt, status);
// 检查任务是否完成
if ("COMPLETED".equals(status)) {
// 任务完成获取视频URL
String videoUrl = result.getVideo().getUrl();
@@ -496,12 +498,12 @@ public class DigitalHumanTaskServiceImpl implements DigitalHumanTaskService {
} else {
throw new Exception("Latentsync 返回视频URL为空");
}
} else if ("FAILED".equals(status)) {
throw new Exception("Latentsync 任务处理失败");
} else if ("FAILED".equals(status) || "ERROR".equals(status)) {
throw new Exception("Latentsync 任务处理失败: " + status);
}
// 等待5秒后再次轮询
Thread.sleep(5000);
// 等待10秒后再次轮询(处理中的任务间隔稍长一些)
Thread.sleep(10000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new Exception("等待Latentsync结果时被中断", e);
@@ -512,7 +514,7 @@ public class DigitalHumanTaskServiceImpl implements DigitalHumanTaskService {
throw new Exception("等待Latentsync结果超时: " + e.getMessage(), e);
}
// 否则等待后重试
Thread.sleep(5000);
Thread.sleep(10000);
}
}