Commit 45a6eebb authored by 王明生's avatar 王明生

fixed: 为BydOpenService添加 ES 连接异常重试逻辑

parent ee828685
......@@ -10,16 +10,22 @@ import com.afanticar.afantiopenapi.model.vo.BydXiaoHongShuMemberDayVO;
import com.afanticar.afantiopenapi.model.vo.BydXiaoHongShuNoteDayVO;
import com.afanticar.core.entity.EsBaseQuery;
import com.afanticar.core.entity.InnerHits;
import com.afanticar.core.exception.ConnectionClosedException;
import com.afanticar.core.exception.EsRuntimeException;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.IOException;
import java.time.LocalDate;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@Slf4j
@Service
public class BydOpenService {
@Resource
......@@ -35,7 +41,7 @@ public class BydOpenService {
@Resource
XiaoHongShuNoteDayMapper noteDayMapper;
@Resource
@Autowired
XiaoHongShuNoteDocService noteDocService;
......@@ -162,7 +168,22 @@ public class BydOpenService {
EsBaseQuery esQuery = new EsBaseQuery();
esQuery.terms("note_id", noteIds);
List<InnerHits<XiaoHongShuNoteDocQTO>> searchResult = noteDocService.search(esQuery).getHits().getHits();
List<InnerHits<XiaoHongShuNoteDocQTO>> searchResult;
int retryCnt = 0;
while (true) {
try {
searchResult = noteDocService.search(esQuery).getHits().getHits();
break;
} catch (ConnectionClosedException e) {
retryCnt += 1;
if (retryCnt >= 3){
throw e;
} else {
// 生成一个简洁的错误日志
log.warn(this.getClass().getName() + ".fetchNoteDaySnap encountered connection closure exception, retry count:\n" + retryCnt, e);
}
}
}
Map<String, String> noteDocs = CollectionUtils.isNotEmpty(searchResult) ? searchResult.stream()
.map(InnerHits::getSource)
.collect(Collectors.toMap(XiaoHongShuNoteDocQTO::getNoteId, XiaoHongShuNoteDocQTO::getDescription))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment