Pārlūkot izejas kodu

增加重试逻辑

tags/v1.0.0^2
林万龙 pirms 3 gadiem
vecāks
revīzija
f61ea49810
3 mainītis faili ar 22 papildinājumiem un 5 dzēšanām
  1. +1
    -1
      src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java
  2. +16
    -3
      src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java
  3. +5
    -1
      src/main/java/com/telpo/dipperposition/task/ScheduleService.java

+ 1
- 1
src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java Parādīt failu

@@ -19,7 +19,7 @@ public interface IDipperDataAsyncTaskService {
* 同步任务
*
*/
void pullAstEPH();
void pullAstEPH(int tryTimes) throws InterruptedException;


/**


+ 16
- 3
src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java Parādīt failu

@@ -10,6 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import static java.lang.Thread.sleep;

/**
* @program: DipperDataAsyncTaskServiceImpl
* @description: 获取星历数据。
@@ -31,13 +33,20 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi

@Override
@Async("asyncServiceExecutor")
public void pullAstEPH() {
public void pullAstEPH(int tryTimes) throws InterruptedException {
if (tryTimes==0) {
return;
} else {
tryTimes--;
}
// (1) 发送bds获取星历数据
byte[] dipperData = pullEPHFromDipper();

// (2) 获取星历数据
if (dipperData == null) {
log.error("获取星历数据错误,取不到星历数据。");
sleep(10000);
pullAstEPH(tryTimes);
} else {
// 保存到DB或者缓存
log.info("保存到DB或者缓存");
@@ -65,7 +74,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi
String hexIn = astTimeCmd + checkSum.substring(0,2) + " " + checkSum.substring(2,4);

byte[] sendResult = null;
String ackAckCheckRef = "233E010102000421293C";
//String ackAckCheckRef = "233E010102000421293C";
sendResult = client.sendCmd(hexIn);
client.closeConnection();

@@ -77,7 +86,11 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi
// String dipperData = pullEPHFromDipper();
byte[] dipperData;
if (!redisUtil.hasKey(DIPPER_DATA_KEY)) {
this.pullAstEPH();
try {
this.pullAstEPH(1);
} catch (InterruptedException e) {
log.error("获取星历数据发生异常:", e);
}
}

dipperData = (byte[])redisUtil.get(DIPPER_DATA_KEY);


+ 5
- 1
src/main/java/com/telpo/dipperposition/task/ScheduleService.java Parādīt failu

@@ -31,7 +31,11 @@ public class ScheduleService {
log.info("开始星历数据同步!");
// 获取推送失败的记录
try {
dipperDataAsyncTaskService.pullAstEPH();
// 如果失败,则可以等待10秒再获取1次。
int tryTimes = 2;
dipperDataAsyncTaskService.pullAstEPH(tryTimes);
} catch (InterruptedException e) {
log.error("获取星历数据重试睡眠发生异常:", e);
} catch (Exception e) {
log.error("执行定时获取星历数据发生异常:", e);
}


Notiek ielāde…
Atcelt
Saglabāt