Added 3 attempts in upsert aggregation_status

This commit is contained in:
Luca Frosini 2024-03-08 11:47:26 +01:00
parent e2bcfc016a
commit 74349c3253
1 changed files with 11 additions and 1 deletions

View File

@ -14,6 +14,7 @@ import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.gcube.accounting.aggregator.aggregation.AggregationInfo;
import org.gcube.accounting.aggregator.aggregation.AggregationType;
@ -205,7 +206,7 @@ public class PostgreSQLConnector extends PersistencePostgreSQL implements Aggreg
@Override
public void upsertAggregationStatus(AggregationStatus aggregationStatus) throws Exception {
for(int i=1; i<=3; i++){
for(int i=0; i<3; i++){
try {
Connection connection = getConnection();
Statement statement = connection.createStatement();
@ -217,6 +218,15 @@ public class PostgreSQLConnector extends PersistencePostgreSQL implements Aggreg
connection.commit();
break;
}catch (Throwable e) {
if(i<3) {
long delay = TimeUnit.MILLISECONDS.toMillis(100);
logger.error("Unable to upsert aggregation status at attemp {}. Retrying in {} millis.", i, delay, e);
Thread.sleep(delay);
}else {
logger.error("Unable to upsert aggregation status.", e);
throw e;
}
} finally {
connection.close();
}
}