Skip to content

Commit

Permalink
连续错误检测
Browse files Browse the repository at this point in the history
  • Loading branch information
luoye663 committed Oct 12, 2020
1 parent d1147a4 commit 13bd639
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 7 deletions.
33 changes: 33 additions & 0 deletions src/main/java/io/qyi/e5/config/Start.java
Original file line number Diff line number Diff line change
@@ -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();*/

}
}
26 changes: 23 additions & 3 deletions src/main/java/io/qyi/e5/service/task/impl/TaskImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -41,6 +42,9 @@ public class TaskImpl implements ITask {
@Autowired
IOutlookLogService outlookLogService;

@Value("${outlook.error.countMax}")
int errorCountMax;

@Override
@Async
public void sendTaskOutlookMQ(int github_id) {
Expand Down Expand Up @@ -83,15 +87,31 @@ public boolean executeE5(int github_id) {
return false;
}
boolean isExecuteE5 ;
String errorKey = "user.mq:" + github_id + ":error";
try {
int mail_count = outlookService.getMailList(Outlook);
outlookLogService.addLog(github_id, "ok", 1, "读取邮件数量:" + mail_count);
if (redisUtil.hasKey(errorKey)) {
redisUtil.del(errorKey);
}
isExecuteE5 = true;
} catch (Exception e) {
e.printStackTrace();
outlookLogService.addLog(github_id, "error", 0, e.getMessage());
outlookLogService.addLog(github_id, "error", 0, "检测到错误,下次将不再自动调用,请修正错误后再授权开启续订。" );
isExecuteE5 = false;
/*连续错误判断*/
if (!redisUtil.hasKey(errorKey)) {
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;
}
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/io/qyi/e5/util/redis/RedisUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ public boolean expire(String key, long time) {

/**
* 删除所有键值对
*
* @throws
* @title deleteALl
* @description
* @author 落叶随风
* @updateTime 2020/4/22 22:53
* @throws
*/
public void deleteALL() {
Set<String> keys = redisTemplate.keys("*");
Expand Down Expand Up @@ -581,7 +582,9 @@ public long lRemove(String key, long count, Object value) {
return 0;
}
}

/**
* @throws
* @title lRemove
* @description
* @author 落叶随风
Expand All @@ -590,16 +593,23 @@ public long lRemove(String key, long count, Object value) {
* @param: value
* @updateTime 2020/2/4 14:59
* @return: long
* @throws
*/
public boolean lTrim(String key, long start, long end) {
try {
redisTemplate.opsForList().trim(key,start,end);
redisTemplate.opsForList().trim(key, start, end);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}

}
public void reName(String old, String new_key) {
redisTemplate.rename(old, new_key);
}

public void delAll() {
Set<String> keys = redisTemplate.keys("*");
redisTemplate.delete(keys);
}
}

0 comments on commit 13bd639

Please sign in to comment.