TASK:generate 修复逻辑Bug

This commit is contained in:
2024-01-25 13:37:17 +08:00
parent 65bed9dada
commit c35a188abb
7 changed files with 75 additions and 44 deletions

View File

@@ -123,7 +123,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
generateThroughImageTextDTO.getLevel1Type().equals(PRINT_BOARD.getRealName()) ? "print" : "moodboard";
AsyncCallerUtil asyncCallerUtil = new AsyncCallerUtil();
List<String> generatedSketchUrl = asyncCallerUtil.generate(new GenerateToPythonDTO(accountId, Objects.isNull(collectionElement) ? "" : collectionElement.getUrl(),
category, text, mode, "1", generateThroughImageTextDTO.getGender() ,generateThroughImageTextDTO.getUniqueId()));
category, text, mode, "1", generateThroughImageTextDTO.getGender(), generateThroughImageTextDTO.getUniqueId()));
// List<String> generatedSketchUrl = pythonService.generateSketchOrPrint(new GenerateToPythonDTO(accountId, Objects.isNull(elementId) ? null : collectionElement.getUrl(),
// category, text, mode, "1", generateThroughImageTextDTO.getGender()));
log.info("generate 响应 " + generatedSketchUrl);
@@ -336,7 +336,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
num++;
}
// 无依据确定的数字
if (num > 10){
if (num > 10) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
@@ -412,9 +412,9 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
return new GenerateCollectionVO(generateId, null, generatedCollectionItems);
}
public Generate selectByUniqueId(String uniqueId){
public Generate selectByUniqueId(String uniqueId) {
QueryWrapper<Generate> qw = new QueryWrapper<>();
qw.eq("unique_id",uniqueId);
qw.eq("unique_id", uniqueId);
return getOne(qw);
}
@@ -423,19 +423,22 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
public void cancelGenerate(String uniqueId) {
// 1、确认当前消息是否还在排队中
Boolean exists = redisUtil.isElementExistsInZSet(consumptionOrderKey, uniqueId);
if (exists) {
Boolean flag = Boolean.FALSE;
if (exists) flag = redisUtil.getRank(consumptionOrderKey, uniqueId) > 1L ? Boolean.TRUE : Boolean.FALSE;
// 不管flag的默认值是true还是false只要exists为false&& 将短路
if (exists && flag) {
// 1.1、将需要取消的唯一id加入redis以便及时取消生成
redisUtil.addToSet(cancelSetKey, uniqueId);
// 1.2 将需要取消的id从redis的ConsumptionOrder中删除
redisUtil.removeFromZSet(consumptionOrderKey, uniqueId);
}else {
} else {
// 2、判断该消息是否异常
boolean hasKey = redisUtil.isElementExistsInMap(exceptionMapKey, uniqueId);
// 3、判断该消息是否已经消费结束
Boolean existsInResult = redisUtil.isElementExistsInMap(resultMapKey, uniqueId);
if (!hasKey && !existsInResult){
if (!hasKey && !existsInResult) {
// 设置取等待状态为false
AsyncCallerUtil.waitingStatus.put(uniqueId,false);
AsyncCallerUtil.waitingStatus.put(uniqueId, false);
// 3、直接发送取消请求到python端
pythonService.cancelGenerateTask(uniqueId);
}