fix: 定时器ip校验
This commit is contained in:
@@ -15,6 +15,8 @@ import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@@ -39,7 +41,7 @@ public class JobRunner implements ApplicationRunner {
|
||||
log.info("--------------------注入定时任务---------------------");
|
||||
List<SysQuartzJob> quartzJobs = quartzJobService.findByIsPauseIsFalse();
|
||||
quartzJobs.forEach(job -> {
|
||||
if (localIp.equals(job.getJob_ip())) {
|
||||
if (judgmentIp(job.getJob_ip())) {
|
||||
log.info("定时任务:{}, 执行ip: {}, 定时任务开启", job.getJob_name(), localIp);
|
||||
System.out.println("定时任务: " + job.getJob_name() + ", 执行ip: " + localIp + ", 定时任务开启");
|
||||
quartzManage.addJob(job);
|
||||
@@ -52,4 +54,9 @@ public class JobRunner implements ApplicationRunner {
|
||||
log.info("--------------------定时任务注入完成---------------------");
|
||||
}
|
||||
|
||||
public static Boolean judgmentIp(String ip) {
|
||||
return NetUtil.localAddressList(null).stream()
|
||||
.anyMatch(inet -> ip.equals(inet.getHostAddress()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user