|
@@ -1,6 +1,9 @@
|
|
|
package com.zanxiang.game.data.serve.task;
|
|
|
|
|
|
+import com.zanxiang.game.data.serve.pojo.properties.SmsProperties;
|
|
|
import com.zanxiang.game.data.serve.service.IGameMonitorAlarmService;
|
|
|
+import com.zanxiang.module.sms.pojo.SendResult;
|
|
|
+import com.zanxiang.module.sms.service.impl.AliSmsService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -10,6 +13,8 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.*;
|
|
|
|
|
|
/**
|
|
@@ -26,6 +31,12 @@ public class GameMonitorAlarmTask {
|
|
|
@Autowired
|
|
|
private IGameMonitorAlarmService gameMonitorAlarmService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private SmsProperties smsProperties;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AliSmsService aliSmsService;
|
|
|
+
|
|
|
private ExecutorService taskScheduler = Executors.newSingleThreadExecutor();
|
|
|
|
|
|
|
|
@@ -54,6 +65,7 @@ public class GameMonitorAlarmTask {
|
|
|
log.info("定时任务游戏监控告警出错", e);
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
+
|
|
|
log.error("定时任务游戏监控告警出错", e);
|
|
|
}
|
|
|
});
|
|
@@ -61,10 +73,21 @@ public class GameMonitorAlarmTask {
|
|
|
//两分钟执行不完就超时
|
|
|
future.get(120, TimeUnit.SECONDS);
|
|
|
} catch (Exception e) {
|
|
|
+ sendMsg("定时任务游戏监控告警超时");
|
|
|
log.error("定时任务游戏监控告警超时", e);
|
|
|
future.cancel(true);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void sendMsg(String msg) {
|
|
|
+ log.info("发送告警消息:{}", msg);
|
|
|
+ Date date = new Date();
|
|
|
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ Map<String, String> params = new HashMap<>();
|
|
|
+ params.put(smsProperties.getMsgParamName(), msg);
|
|
|
+ params.put(smsProperties.getTimeParamName(),formatter.format(date));
|
|
|
+ String number = "15765577867";
|
|
|
+ aliSmsService.send(smsProperties.getDefaultSignName(), smsProperties.getDefaultStstemErrorTemplate(), params, number);
|
|
|
+ }
|
|
|
|
|
|
}
|