odoo增加报错重试机制

畅捷通报表
YXY 1 year ago
parent 7902fcb255
commit 56c552e2d1

@ -105,7 +105,7 @@ public abstract class OdooAbstrackob {
LarkTableRelation tableRelation = context.getTableRelation(); LarkTableRelation tableRelation = context.getTableRelation();
LarkTableRequest larkRequest = new LarkTableRequest(companyRelation.getAppId(), companyRelation.getSecret(), tableRelation.getToAppToken(), tableRelation.getToTableId()); LarkTableRequest larkRequest = new LarkTableRequest(companyRelation.getAppId(), companyRelation.getSecret(), tableRelation.getToAppToken(), tableRelation.getToTableId());
List<String> errorList = new ArrayList<>(); List<String> errorList = new ArrayList<>();
batchCreate(context, pageMap, larkRequest, errorList); batchCreate(context, pageMap, larkRequest, errorList,1);
if (!CollectionUtils.isEmpty(errorList)) { if (!CollectionUtils.isEmpty(errorList)) {
String errorKey = String.join(",", errorList); String errorKey = String.join(",", errorList);
throw new RuntimeException(String.format("存在同步失败的记录 %s", errorKey)); throw new RuntimeException(String.format("存在同步失败的记录 %s", errorKey));
@ -113,7 +113,7 @@ public abstract class OdooAbstrackob {
} }
private void batchCreate(OdooContext context, Map<String, Integer> pageMap, LarkTableRequest larkRequest, List<String> errorList) { private void batchCreate(OdooContext context, Map<String, Integer> pageMap, LarkTableRequest larkRequest, List<String> errorList,Integer retryCount) {
//查询结果 //查询结果
List<Object> dateList = new ArrayList<>(); List<Object> dateList = new ArrayList<>();
List<Integer> retryPageList = new ArrayList<>(); List<Integer> retryPageList = new ArrayList<>();
@ -134,9 +134,9 @@ public abstract class OdooAbstrackob {
} }
pageMap.put(PAGE_OFFSET_KEY, pageMap.get(PAGE_OFFSET_KEY) + PAGE_SIZE); pageMap.put(PAGE_OFFSET_KEY, pageMap.get(PAGE_OFFSET_KEY) + PAGE_SIZE);
} while (dateList == null || (CollectionUtils.isNotEmpty(dateList) && dateList.size() == PAGE_SIZE)); } while (dateList == null || (CollectionUtils.isNotEmpty(dateList) && dateList.size() == PAGE_SIZE));
if (retryPageList.size() > 0) { if (retryPageList.size() > 0 && retryCount <= 3) {
pageMap.put(PAGE_OFFSET_KEY, retryPageList.get(0) + PAGE_SIZE); pageMap.put(PAGE_OFFSET_KEY, retryPageList.get(0) + PAGE_SIZE);
batchCreate(context, pageMap, larkRequest, errorList); batchCreate(context, pageMap, larkRequest, errorList,retryCount + 1);
} }
} }

Loading…
Cancel
Save