diff --git a/src/main/java/com/coco/boot/service/impl/CoCoPilotServiceImpl.java b/src/main/java/com/coco/boot/service/impl/CoCoPilotServiceImpl.java index 72cb8b9..3d9303d 100644 --- a/src/main/java/com/coco/boot/service/impl/CoCoPilotServiceImpl.java +++ b/src/main/java/com/coco/boot/service/impl/CoCoPilotServiceImpl.java @@ -83,7 +83,7 @@ public R uploadGhu(String data) { map.put(ghu, "存活"); ghus.add(ghu); } else if (response.getStatusCode() == HttpStatus.TOO_MANY_REQUESTS) { - Integer retry = Integer.valueOf(response.getHeaders().get(HEADER_RETRY).get(0)); + setCoolkey(ghu,response); log.info("upload 存活校验限流: {}, 返回: {}", ghu, response.getBody()); } else { map.put(ghu, "失效"); @@ -250,28 +250,7 @@ private ResponseEntity getBaseProxyResponse(Object requestBody, String p } else { ghuAliveKey.remove(ghu); if (response.getStatusCode() == HttpStatus.TOO_MANY_REQUESTS) { - String retryAfter = response.getHeaders().getFirst(HEADER_RETRY); - // 默认 600秒 - long time = 120; - if (StringUtil.isNotBlank(retryAfter)) { - try { - time = Long.parseLong(retryAfter); - } catch (NumberFormatException e) { - } - } - - if (time > 1000) { - redissonClient.getSet(GHU_NO_ALIVE_KEY, StringCodec.INSTANCE).addAsync(ghu); - } else { - RMapCache collingMap = redissonClient.getMapCache(GHU_COOLING_KEY); - if (!collingMap.isExists()) { - collingMap.addListener((EntryExpiredListener) event -> { - // expired key - redissonClient.getSet(GHU_ALIVE_KEY, StringCodec.INSTANCE).add(event.getKey()); - }); - } - collingMap.put(ghu, 1, time + 5, TimeUnit.SECONDS); - } + setCoolkey(ghu,response); } else { redissonClient.getSet(GHU_NO_ALIVE_KEY, StringCodec.INSTANCE).addAsync(ghu); } @@ -307,4 +286,29 @@ public String getGhu(RSet ghuAliveKey) { } return null; } + + private void setCoolkey(String ghu, ResponseEntity response) { + String retryAfter = response.getHeaders().getFirst(HEADER_RETRY); + // 默认 600秒 + long time = 120; + if (StringUtil.isNotBlank(retryAfter)) { + try { + time = Long.parseLong(retryAfter); + } catch (NumberFormatException e) {} + } + + if (time > 1000) { + redissonClient.getSet(GHU_NO_ALIVE_KEY, StringCodec.INSTANCE).addAsync(ghu); + } else { + RMapCache collingMap = redissonClient.getMapCache(GHU_COOLING_KEY); + if (!collingMap.isExists()) { + collingMap.addListener((EntryExpiredListener) event -> { + // expired key + redissonClient.getSet(GHU_ALIVE_KEY, StringCodec.INSTANCE).add(event.getKey()); + }); + } + collingMap.put(ghu, 1, time+5, TimeUnit.SECONDS); + } + } + }