连续错误检测

This commit is contained in:
Luoye 2020-10-12 17:16:14 +08:00
parent 9439a49358
commit 2f76bcb973
3 changed files with 70 additions and 7 deletions

View File

@ -0,0 +1,33 @@
package io.qyi.e5.config;
import io.qyi.e5.service.task.ITask;
import io.qyi.e5.util.redis.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
/**
* @program: e5
* @description:
* @author: 落叶随风
* @create: 2020-10-12 16:58
**/
@Component
@Slf4j
public class Start {
@Autowired
RedisUtil redisUtil;
@Autowired
ITask Task;
@PostConstruct
public void initRedis() {
log.info("清空redis...... ");
redisUtil.delAll();
/* log.info("重新添加队列...... ");
Task.sendTaskOutlookMQALL();*/
}
}

View File

@ -12,6 +12,7 @@ import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.connection.CorrelationData; import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -41,6 +42,9 @@ public class TaskImpl implements ITask {
@Autowired @Autowired
IOutlookLogService outlookLogService; IOutlookLogService outlookLogService;
@Value("${outlook.error.countMax}")
int errorCountMax;
@Override @Override
@Async @Async
public void sendTaskOutlookMQ(int github_id) { public void sendTaskOutlookMQ(int github_id) {
@ -83,15 +87,31 @@ public class TaskImpl implements ITask {
return false; return false;
} }
boolean isExecuteE5 ; boolean isExecuteE5 ;
String errorKey = "user.mq:" + github_id + ":error";
try { try {
int mail_count = outlookService.getMailList(Outlook); int mail_count = outlookService.getMailList(Outlook);
outlookLogService.addLog(github_id, "ok", 1, "读取邮件数量:" + mail_count); outlookLogService.addLog(github_id, "ok", 1, "读取邮件数量:" + mail_count);
if (redisUtil.hasKey(errorKey)) {
redisUtil.del(errorKey);
}
isExecuteE5 = true; isExecuteE5 = true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
outlookLogService.addLog(github_id, "error", 0, e.getMessage()); /*连续错误判断*/
outlookLogService.addLog(github_id, "error", 0, "检测到错误,下次将不再自动调用,请修正错误后再授权开启续订。" ); if (!redisUtil.hasKey(errorKey)) {
isExecuteE5 = false; redisUtil.set(errorKey, 1);
isExecuteE5 = true;
} else {
int error_count = (int)redisUtil.get(errorKey);
if (error_count >= errorCountMax) {
outlookLogService.addLog(github_id, "error", 0, e.getMessage());
outlookLogService.addLog(github_id, "error", 0, "检测到3次连续错误下次将不再自动调用请修正错误后再授权开启续订。");
isExecuteE5 = false;
} else {
redisUtil.incr(errorKey, 1);
isExecuteE5 = true;
}
}
} }
return isExecuteE5; return isExecuteE5;
} }

View File

@ -51,11 +51,12 @@ public class RedisUtil {
/** /**
* 删除所有键值对 * 删除所有键值对
*
* @throws
* @title deleteALl * @title deleteALl
* @description * @description
* @author 落叶随风 * @author 落叶随风
* @updateTime 2020/4/22 22:53 * @updateTime 2020/4/22 22:53
* @throws
*/ */
public void deleteALL() { public void deleteALL() {
Set<String> keys = redisTemplate.keys("*"); Set<String> keys = redisTemplate.keys("*");
@ -581,7 +582,9 @@ public class RedisUtil {
return 0; return 0;
} }
} }
/** /**
* @throws
* @title lRemove * @title lRemove
* @description * @description
* @author 落叶随风 * @author 落叶随风
@ -590,11 +593,10 @@ public class RedisUtil {
* @param: value * @param: value
* @updateTime 2020/2/4 14:59 * @updateTime 2020/2/4 14:59
* @return: long * @return: long
* @throws
*/ */
public boolean lTrim(String key, long start, long end) { public boolean lTrim(String key, long start, long end) {
try { try {
redisTemplate.opsForList().trim(key,start,end); redisTemplate.opsForList().trim(key, start, end);
return true; return true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -602,4 +604,12 @@ public class RedisUtil {
} }
} }
} public void reName(String old, String new_key) {
redisTemplate.rename(old, new_key);
}
public void delAll() {
Set<String> keys = redisTemplate.keys("*");
redisTemplate.delete(keys);
}
}