remove sneaky exceptions

This commit is contained in:
RM
2026-10-01 21:29:56 +03:00
parent 01ea006d95
commit c6183a88ef
2 changed files with 28 additions and 25 deletions

View File

@@ -8,7 +8,6 @@ import com.pledge.torgi.service.DownloadHeadlessService;
import com.pledge.torgi.service.Lot; import com.pledge.torgi.service.Lot;
import com.pledge.torgi.service.SendEmailService; import com.pledge.torgi.service.SendEmailService;
import com.pledge.torgi.utils.StartParams; import com.pledge.torgi.utils.StartParams;
import lombok.SneakyThrows;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
@@ -139,29 +138,32 @@ public class DownloadHeadlessController {
fis.close(); fis.close();
} }
@SneakyThrows
public void richData() { public void richData() {
List<MissedData> all = missedDataRepository.findAll(PageRequest.of(0, 10)).toList(); try {
DownloadHeadlessService downloadHeadlessService = new DownloadHeadlessService(); List<MissedData> all = missedDataRepository.findAll(PageRequest.of(0, 10)).toList();
for (MissedData missedCadastral : all) { DownloadHeadlessService downloadHeadlessService = new DownloadHeadlessService();
Map<String, Lot> currentContent = downloadHeadlessService.downloadExcel(0, String.format(CUSTOM_EXCEL_LINK, missedCadastral.getCadastral())); for (MissedData missedCadastral : all) {
logger.error("get content by cadastral {} {}", missedCadastral.getCadastral(), currentContent.size()); Map<String, Lot> currentContent = downloadHeadlessService.downloadExcel(0, String.format(CUSTOM_EXCEL_LINK, missedCadastral.getCadastral()));
if (!currentContent.isEmpty()) { logger.error("get content by cadastral {} {}", missedCadastral.getCadastral(), currentContent.size());
List<TorgiEvent> newEvents = new ArrayList<>(); if (!currentContent.isEmpty()) {
Set<String> contentByCadastral = new HashSet<>(); List<TorgiEvent> newEvents = new ArrayList<>();
eventRepository.findAllByFullInfoLikeOrderByCreatedAtDesc("%" + missedCadastral.getCadastral() + "%").forEach(event -> contentByCadastral.add(event.getKey())); Set<String> contentByCadastral = new HashSet<>();
eventRepository.findAllByFullInfoLikeOrderByCreatedAtDesc("%" + missedCadastral.getCadastral() + "%").forEach(event -> contentByCadastral.add(event.getKey()));
for (String key : currentContent.keySet()) { for (String key : currentContent.keySet()) {
if (!contentByCadastral.contains(key)) { if (!contentByCadastral.contains(key)) {
newEvents.add(new TorgiEvent(key, currentContent.get(key))); newEvents.add(new TorgiEvent(key, currentContent.get(key)));
content.add(key); content.add(key);
logger.error("added new missed content"); logger.error("added new missed content");
}
} }
eventRepository.saveAll(newEvents);
} }
eventRepository.saveAll(newEvents); missedDataRepository.delete(missedCadastral);
Thread.sleep(5000);
} }
missedDataRepository.delete(missedCadastral); } catch (Exception ex) {
Thread.sleep(5000); logger.error("Exception during rich data", ex);
} }
} }
} }

View File

@@ -3,7 +3,6 @@ package com.pledge.torgi.service;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.pledge.torgi.model.TorgiEvent; import com.pledge.torgi.model.TorgiEvent;
import com.pledge.torgi.repositories.TorgiEventRepository; import com.pledge.torgi.repositories.TorgiEventRepository;
import lombok.SneakyThrows;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
@@ -12,9 +11,7 @@ import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.data.domain.PageRequest;
import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
@@ -43,7 +40,6 @@ public class DownloadHeadlessService {
private static final int COL_FINAL_PRICE = 27; private static final int COL_FINAL_PRICE = 27;
private static final int COL_FULL_INFO = 29; private static final int COL_FULL_INFO = 29;
@SneakyThrows
public Map<String, Lot> downloadExcel(int retryCount, String link) { public Map<String, Lot> downloadExcel(int retryCount, String link) {
try { try {
HttpURLConnection connection = (HttpURLConnection) new URL(link).openConnection(); HttpURLConnection connection = (HttpURLConnection) new URL(link).openConnection();
@@ -85,8 +81,13 @@ public class DownloadHeadlessService {
return new HashMap<>(); return new HashMap<>();
} }
} }
Thread.sleep(1000); try {
return downloadExcel(retryCount + 1, link); Thread.sleep(1000);
return downloadExcel(retryCount + 1, link);
} catch (Exception ex) {
logger.error("Exception during retry downloadExcel by link {}", link, ex);
return new HashMap<>();
}
} }
private Lot extractDataFromRow(Row row, String cadastral) { private Lot extractDataFromRow(Row row, String cadastral) {