v1.0.13 - Retry logic (3 intentos) + timeout 30s/60s
This commit is contained in:
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
|
|||||||
Bundle-ManifestVersion: 2
|
Bundle-ManifestVersion: 2
|
||||||
Bundle-Name: BCV Exchange Rate Plugin
|
Bundle-Name: BCV Exchange Rate Plugin
|
||||||
Bundle-SymbolicName: com.venezuela.bcvrate;singleton:=true
|
Bundle-SymbolicName: com.venezuela.bcvrate;singleton:=true
|
||||||
Bundle-Version: 1.0.12
|
Bundle-Version: 1.0.13
|
||||||
Bundle-Vendor: Ezerpa
|
Bundle-Vendor: Ezerpa
|
||||||
Bundle-RequiredExecutionEnvironment: JavaSE-11
|
Bundle-RequiredExecutionEnvironment: JavaSE-11
|
||||||
Bundle-ActivationPolicy: lazy
|
Bundle-ActivationPolicy: lazy
|
||||||
|
|||||||
@@ -149,11 +149,19 @@ public class BCVApiService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private BCVRateResponse getRateFromBCVWebsite() {
|
private BCVRateResponse getRateFromBCVWebsite() {
|
||||||
|
int maxRetries = 3;
|
||||||
|
for (int attempt = 1; attempt <= maxRetries; attempt++) {
|
||||||
try {
|
try {
|
||||||
log.info("Iniciando scraping de BCV website...");
|
log.info("Scraping BCV - Intento " + attempt + "/" + maxRetries);
|
||||||
String html = httpGetHtml(BCV_WEBSITE);
|
String html = httpGetHtml(BCV_WEBSITE);
|
||||||
if (html == null) {
|
if (html == null) {
|
||||||
log.warning("No se pudo obtener pagina BCV (httpGetHtml returned null)");
|
log.warning("Intento " + attempt + "/" + maxRetries + ": No se pudo obtener pagina BCV");
|
||||||
|
if (attempt < maxRetries) {
|
||||||
|
log.info("Reintentando en 5 segundos...");
|
||||||
|
Thread.sleep(5000);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
log.severe("Scraping BCV fallo despues de " + maxRetries + " intentos (timeout o error de conexion)");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
log.info("Pagina BCV obtenida, longitud: " + html.length());
|
log.info("Pagina BCV obtenida, longitud: " + html.length());
|
||||||
@@ -180,15 +188,26 @@ public class BCVApiService {
|
|||||||
if (effectiveDate == null) {
|
if (effectiveDate == null) {
|
||||||
effectiveDate = new SimpleDateFormat("yyyy-MM-dd").format(new java.util.Date());
|
effectiveDate = new SimpleDateFormat("yyyy-MM-dd").format(new java.util.Date());
|
||||||
}
|
}
|
||||||
log.info("Scraping BCV exitoso: USD=" + dollar + " effective=" + effectiveDate);
|
log.info("Scraping BCV exitoso (intento " + attempt + "): USD=" + dollar + " effective=" + effectiveDate);
|
||||||
return new BCVRateResponse(dollar, effectiveDate);
|
return new BCVRateResponse(dollar, effectiveDate);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch (Exception e) {
|
} catch (InterruptedException ie) {
|
||||||
log.log(Level.WARNING, "Error scraping BCV website: " + e.getMessage(), e);
|
Thread.currentThread().interrupt();
|
||||||
|
log.warning("Scraping BCV interrumpido");
|
||||||
return null;
|
return null;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warning("Intento " + attempt + "/" + maxRetries + ": Error scraping BCV: " + e.getMessage());
|
||||||
|
if (attempt < maxRetries) {
|
||||||
|
log.info("Reintentando en 5 segundos...");
|
||||||
|
try { Thread.sleep(5000); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); }
|
||||||
|
} else {
|
||||||
|
log.severe("Scraping BCV fallo despues de " + maxRetries + " intentos: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private BigDecimal extractUSD(String json) {
|
private BigDecimal extractUSD(String json) {
|
||||||
Matcher m = Pattern.compile("\"USD\"\\s*:\\s*([0-9.]+)").matcher(json);
|
Matcher m = Pattern.compile("\"USD\"\\s*:\\s*([0-9.]+)").matcher(json);
|
||||||
|
|||||||
Reference in New Issue
Block a user