feat: shutdown graceful

dev
huangfeng 8 months ago
parent a1984a94b6
commit afc81c91f8

@ -71,6 +71,7 @@ public class IecServerService {
@PreDestroy
private void stop() {
log.info("关闭IecServer服务.");
RealTimeDataService.iecServer = null;
iecServer.close();
}

@ -83,11 +83,13 @@ public class RealTimeDataService {
IcdIed ied = optional.get();
ied.setStart(Constants.FALSE);
iedRepository.save(ied);
log.info("61850停止订阅, ied=" + ied.getName() + ", ip=" + ied.getIp());
}
}
@PreDestroy
private void stop() {
log.info("关闭61850订阅服务.");
Iterator<Integer> it = clientMap.keySet().iterator();
while (it.hasNext()) {
Integer key = it.next();

@ -15,6 +15,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import java.io.File;
import java.util.Date;
@ -39,6 +40,13 @@ public class AmpliDownloadTask {
@Resource
WebSocketServer webSocketServer;
int shutdown = 0;
@PreDestroy
private void preDestroy() {
shutdown = 1;
}
@Scheduled(cron = "0 10 * * * ?")
public void downloadAll() {
List<RemoteConfig> configList = configService.listAll();
@ -60,6 +68,9 @@ public class AmpliDownloadTask {
// 下载一个远端服务器
private void downloadServer(RemoteConfig config) throws Exception {
if (shutdown == 1) {
return;
}
if (config.getActive() == null || config.getActive().intValue() == Constants.FALSE) {
return;
}
@ -86,6 +97,9 @@ public class AmpliDownloadTask {
}
private void downloadPath(String remotePath, RemoteConfig config, SFTPTool sftpTool) throws Exception {
if (shutdown == 1) {
return;
}
String str = "abcd" + remotePath.replaceAll("/", "").replaceAll("\\\\", "");
str = str.substring(str.length() - 4);
String localPath = folder + "/" + config.getIp() + "/" + str;
@ -100,6 +114,9 @@ public class AmpliDownloadTask {
private void downloadFile(String remotePath, String filename,
String localPath, RemoteConfig config, SFTPTool sftpTool) throws Exception {
if (shutdown == 1) {
return;
}
if (StringUtils.isBlank(config.getSuffix()) || filename.toLowerCase().endsWith(config.getSuffix().toLowerCase())) {
RemoteDownload item = new RemoteDownload();
item.setConfigId(config.getId());

@ -9,6 +9,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Calendar;
@ -33,6 +34,13 @@ public class Client61850Task {
@Resource
NSensorRepository sensorRepository;
int shutdown = 0;
@PreDestroy
private void preDestroy() {
shutdown = 1;
}
@Scheduled(cron = "0 * * * * ?")
public void collectAll() {
if (!enable) {
@ -84,6 +92,9 @@ public class Client61850Task {
}
private void collectIcdFile(IcdFile icdFile, List<Rptparamindex> rptList) {
if (shutdown == 1) {
return;
}
List<IcdIed> iedList = iedRepository.findByIcdFileId(icdFile.getId());
if (!CollectionUtils.isEmpty(iedList)) {
for (IcdIed ied : iedList) {

@ -15,6 +15,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@ -38,6 +39,13 @@ public class I2syncTask {
@Resource
WebSocketServer webSocketServer;
int shutdown = 0;
@PreDestroy
private void preDestroy() {
shutdown = 1;
}
@Scheduled(initialDelay = 60 * 1000, fixedDelay = 30 * 60 * 1000)
public void syncAll() {
List<I2syncConfig> configList = i2syncService.listConfig();
@ -55,7 +63,7 @@ public class I2syncTask {
} catch (Exception e) {
log.error("I2syncTask.syncAll error.", e);
String str = "i2同步导出数据异常: " + e.getMessage();
webSocketServer.sendMessage(str , null);
webSocketServer.sendMessage(str, null);
dingTalkPushUtil.pushText(str);
}
}
@ -63,7 +71,10 @@ public class I2syncTask {
// 同步一个类型
private void syncOneConfig(I2syncConfig config) throws Exception {
log.info("I2syncTask.syncOneConfig " + config.getTypeName());
if (shutdown == 1) {
return;
}
log.info("I2syncTask 同步一个类型 " + config.getTypeName());
List<I2syncField> fieldList = i2syncService.listFieldConfig(config.getTableName());
if (CollectionUtils.isEmpty(fieldList)) {
log.info("该类型未配置同步字段.");
@ -89,6 +100,9 @@ public class I2syncTask {
// 同步一个装置
private void syncOneSensor(NSensor sensor, I2syncConfig config,
List<I2syncField> fieldList, List<ModevTypePoint> points) throws Exception {
if (shutdown == 1) {
return;
}
I2syncRecord record;
List<I2syncRecord> recordList = recordRepository.findByEqmid(sensor.getDevId());
if (CollectionUtils.isEmpty(recordList)) {

@ -15,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import java.util.*;
@ -32,6 +33,13 @@ public class RuleCheckTask {
@Resource
WebSocketServer webSocketServer;
int shutdown = 0;
@PreDestroy
private void preDestroy() {
shutdown = 1;
}
@Scheduled(initialDelay = 60 * 1000, fixedDelay = 3 * 60 * 1000)
private void checkAll() {
try {
@ -49,6 +57,9 @@ public class RuleCheckTask {
}
private void ruleCheck(WarnRule rule) {
if (shutdown == 1) {
return;
}
try {
NSensor sensor = rule.getNSensor();
ModevTypePoint typePoint = rule.getTypePoint();
@ -68,6 +79,9 @@ public class RuleCheckTask {
}
private void sendWarning(WarnRule rule, TriggerModel model) throws Exception {
if (shutdown == 1) {
return;
}
NSensor sensor = rule.getNSensor();
ModevTypePoint typePoint = rule.getTypePoint();
Warning warning = Warning.builder()
@ -96,7 +110,7 @@ public class RuleCheckTask {
str = str + ", 最后采集时间:" + DateUtil.format(model.getLastDTime());
}
log.warn("触发规则告警: " + str);
webSocketServer.sendMessage(str , warning.getId());
webSocketServer.sendMessage(str, warning.getId());
dingTalkPushUtil.pushText(str);
}

@ -2,6 +2,7 @@ server:
port: 8099
servlet:
context-path: /
shutdown: graceful
spring:
jackson:

@ -2,6 +2,7 @@ server:
port: 8099
servlet:
context-path: /
shutdown: graceful
spring:
jackson:

Loading…
Cancel
Save