|
@@ -114,6 +114,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
|
|
|
|
|
private final MidjourneySessionMapper midjourneySessionMapper;
|
|
private final MidjourneySessionMapper midjourneySessionMapper;
|
|
|
|
|
|
|
|
|
|
+ private final ConcurrentHashMap<String, Object> lockMap = new ConcurrentHashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public MidjourneyUser getUser(String userToken) {
|
|
public MidjourneyUser getUser(String userToken) {
|
|
|
if(StringUtils.isBlank(userToken)){
|
|
if(StringUtils.isBlank(userToken)){
|
|
@@ -768,16 +771,16 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
//失败返还次数
|
|
//失败返还次数
|
|
|
if ("FAILURE".equals(conversation.getStatus()) && !dbConversation.getStatus().equals("MODEL")){
|
|
if ("FAILURE".equals(conversation.getStatus()) && !dbConversation.getStatus().equals("MODEL")){
|
|
|
Integer mode = dbConversation.getMode();
|
|
Integer mode = dbConversation.getMode();
|
|
|
- if (StringUtils.equals("未知频道",conversation.getFailReason())) {
|
|
|
|
|
- redisService.hdel(mode == 1 ? RedisService.key.MIDJOURNEY_FAST_ACCOUNT.getName() : RedisService.key.MIDJOURNEY_ACCOUNT.getName(),dbConversation.getInstanceId().toString());
|
|
|
|
|
- String finalAccountWithMinUsage = dbConversation.getInstanceId().toString();
|
|
|
|
|
- TASK_EXECUTOR.execute(() -> {
|
|
|
|
|
- MidjourneyAccount account = midjourneyAccountService.getOne(Wrappers.lambdaQuery(MidjourneyAccount.class).eq(MidjourneyAccount::getInstanceId, finalAccountWithMinUsage).last("limit 1"));
|
|
|
|
|
- if (account.getStatus()) {
|
|
|
|
|
- midjourneyAccountService.updateStatus(account.getId());
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// if (StringUtils.equals("未知频道",conversation.getFailReason())) {
|
|
|
|
|
+// redisService.hdel(mode == 1 ? RedisService.key.MIDJOURNEY_FAST_ACCOUNT.getName() : RedisService.key.MIDJOURNEY_ACCOUNT.getName(),dbConversation.getInstanceId().toString());
|
|
|
|
|
+// String finalAccountWithMinUsage = dbConversation.getInstanceId().toString();
|
|
|
|
|
+// TASK_EXECUTOR.execute(() -> {
|
|
|
|
|
+// MidjourneyAccount account = midjourneyAccountService.getOne(Wrappers.lambdaQuery(MidjourneyAccount.class).eq(MidjourneyAccount::getInstanceId, finalAccountWithMinUsage).last("limit 1"));
|
|
|
|
|
+// if (account.getStatus()) {
|
|
|
|
|
+// midjourneyAccountService.updateStatus(account.getId());
|
|
|
|
|
+// }
|
|
|
|
|
+// });
|
|
|
|
|
+// }
|
|
|
Object num = redisService.get(RedisService.key.MIDJOURNEY_RELAX_LIMIT.getName() + userId);
|
|
Object num = redisService.get(RedisService.key.MIDJOURNEY_RELAX_LIMIT.getName() + userId);
|
|
|
LambdaUpdateWrapper<MidjourneyUser> wrapper = Wrappers.lambdaUpdate(MidjourneyUser.class)
|
|
LambdaUpdateWrapper<MidjourneyUser> wrapper = Wrappers.lambdaUpdate(MidjourneyUser.class)
|
|
|
.eq(MidjourneyUser::getId, userId);
|
|
.eq(MidjourneyUser::getId, userId);
|
|
@@ -1115,7 +1118,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
public void handleCallback(MidjourneyUserConversation conversation) {
|
|
public void handleCallback(MidjourneyUserConversation conversation) {
|
|
|
String key = RedisService.key.MIDJOURNEY_PROGRESS.getName() + conversation.getTaskId();
|
|
String key = RedisService.key.MIDJOURNEY_PROGRESS.getName() + conversation.getTaskId();
|
|
|
|
|
|
|
|
- synchronized (key.intern()) {
|
|
|
|
|
|
|
+ synchronized (conversation.getTaskId()) {
|
|
|
String currentProgressStr = redisService.getStr(key);
|
|
String currentProgressStr = redisService.getStr(key);
|
|
|
if(StringUtils.isNotBlank(currentProgressStr)){
|
|
if(StringUtils.isNotBlank(currentProgressStr)){
|
|
|
if (StringUtils.isNumeric(currentProgressStr)) {
|
|
if (StringUtils.isNumeric(currentProgressStr)) {
|
|
@@ -1126,8 +1129,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}else {
|
|
}else {
|
|
|
- redisService.set(key, 0, RedisService.key.MIDJOURNEY_PROGRESS.getTimeout());
|
|
|
|
|
- sendProgressToClient(conversation);
|
|
|
|
|
|
|
+ if (redisService.setNx(key, 0, RedisService.key.MIDJOURNEY_PROGRESS.getTimeout())) {
|
|
|
|
|
+ sendProgressToClient(conversation);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|