第6次优化

master
liuyunhu 2024-04-17 21:05:48 +08:00
parent ff7dfdc1e4
commit e70a315159
5 changed files with 36 additions and 26 deletions

View File

@ -2,6 +2,7 @@ package com.lyh;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
/** /**
* @ProjectName: Default (Template) Project * @ProjectName: Default (Template) Project
@ -11,8 +12,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
*/ */
@SpringBootApplication @SpringBootApplication
//@EnableScheduling @EnableScheduling
//@EnableFeignClients
public class LoadCenterApplication { public class LoadCenterApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(LoadCenterApplication.class, args); SpringApplication.run(LoadCenterApplication.class, args);

View File

@ -12,6 +12,7 @@ import com.lyh.domain.resp.Result;
import com.lyh.service.LoadCenterService; import com.lyh.service.LoadCenterService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
@ -36,6 +37,19 @@ public class LoadCenterServiceImpl implements LoadCenterService {
@Autowired @Autowired
private AliYunEcsService aliYunEcsService; private AliYunEcsService aliYunEcsService;
/*
* @Author: LiuYunHu
* @Date: 2024/4/17 20:31
* @Description: IP
* @Param: []
* @Return: void
**/
@Scheduled(cron = "0/2 * * * * ?")
public void refreshEcsIPListCache() {
getEcsIPList();
}
/* /*
* @Author: LiuYunHu * @Author: LiuYunHu
* @Date: 2024/4/15 21:49 * @Date: 2024/4/15 21:49
@ -46,10 +60,6 @@ public class LoadCenterServiceImpl implements LoadCenterService {
@Override @Override
public Result<String> getAssignedServer() { public Result<String> getAssignedServer() {
//刷新一下 实例公网IP列 缓存
this.getEcsIPList();
//从缓存中获取实例公网IP列表 //从缓存中获取实例公网IP列表
if (redis.getCacheList("实例IP列表:").isEmpty()) { if (redis.getCacheList("实例IP列表:").isEmpty()) {
throw new RuntimeException("实例IP列表为空"); throw new RuntimeException("实例IP列表为空");

View File

@ -72,7 +72,7 @@ public class Test {
**/ **/
@org.junit.jupiter.api.Test @org.junit.jupiter.api.Test
public void releaseInstances() throws Exception { public void releaseInstances() throws Exception {
aliYunEcsService.releaseInstances("i-uf624nmh7j2nzlzxnd1u"); aliYunEcsService.releaseInstances("i-uf6dmmscd3b64m0jqs9f");
} }
/* /*