Skip to content

Commit

Permalink
retry
Browse files Browse the repository at this point in the history
  • Loading branch information
jacopocarlini committed Dec 6, 2024
1 parent abd397b commit f98cb08
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 177 deletions.
165 changes: 0 additions & 165 deletions src/main/java/it/gov/pagopa/bizpmingestion/config/LoggingAspect.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
name = "ppWallet-subgraph",
attributeNodes = {
@NamedAttributeNode("ppCreditCard"),
// @NamedAttributeNode("ppPsp"),
@NamedAttributeNode("ppPsp"),
// @NamedAttributeNode("ppPayPal"),
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.gov.pagopa.bizpmingestion.service.impl;

import com.microsoft.azure.functions.annotation.ExponentialBackoffRetry;
import it.gov.pagopa.bizpmingestion.entity.pm.*;
import it.gov.pagopa.bizpmingestion.enumeration.PaymentMethodType;
import it.gov.pagopa.bizpmingestion.model.pm.PMEvent;
Expand All @@ -18,6 +19,10 @@
@Component
public class MapperComponent {

@ExponentialBackoffRetry(
maxRetryCount = 3,
maximumInterval = "00:00:30",
minimumInterval = "00:00:05")
public PMEvent convert(PPTransaction ppTransaction) {

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
import com.azure.spring.data.cosmos.repository.CosmosRepository;
import com.microsoft.azure.functions.annotation.ExponentialBackoffRetry;
import it.gov.pagopa.bizpmingestion.entity.cosmos.execution.BizEventsPMIngestionExecution;
import it.gov.pagopa.bizpmingestion.entity.cosmos.execution.SkippedTransaction;
import it.gov.pagopa.bizpmingestion.entity.pm.PPTransaction;
import it.gov.pagopa.bizpmingestion.model.WrapperObject;
import it.gov.pagopa.bizpmingestion.model.pm.PMEvent;
import it.gov.pagopa.bizpmingestion.model.pm.PMEventPaymentDetail;
import it.gov.pagopa.bizpmingestion.model.pm.PMEventToViewResult;
import it.gov.pagopa.bizpmingestion.repository.*;
import it.gov.pagopa.bizpmingestion.service.IPMEventToViewService;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
Expand Down Expand Up @@ -64,7 +62,7 @@ public BizEventsPMIngestionExecution computeSlice(
int sliceNumber) {
try {
pmIngestionExec.setId(UUID.randomUUID().toString());
List<PPTransaction> ppTrList = ppTransactionRepository.findAll(spec);
List<PPTransaction> ppTrList = getPpTransactions(spec);

List<PMEvent> pmEventList =
ppTrList.stream().map(elem -> mapperComponent.convert(elem)).toList();
Expand All @@ -90,11 +88,19 @@ public BizEventsPMIngestionExecution computeSlice(
pmIngestionExec.getStatus(),
pmIngestionExec.getNumRecordIngested(),
pmIngestionExec.getNumRecordFound(),
LocalDate.parse(pmIngestionExec.getDateFrom()));
LocalDateTime.parse(pmIngestionExec.getDateFrom()).toLocalDate());
}
return pmIngestionExec;
}

@ExponentialBackoffRetry(
maxRetryCount = 3,
maximumInterval = "00:00:30",
minimumInterval = "00:00:05")
private List<PPTransaction> getPpTransactions(Specification<PPTransaction> spec) {
return ppTransactionRepository.findAll(spec);
}

private void handleEventList(
List<PMEvent> pmEventList, BizEventsPMIngestionExecution pmIngestionExec, int sliceNumber) {
pmIngestionExec.setStatus("ALL_COMPLETED");
Expand Down Expand Up @@ -171,13 +177,13 @@ private void handleEventList(
@ExponentialBackoffRetry(
maxRetryCount = 3,
maximumInterval = "00:00:30",
minimumInterval = "00:00:5")
minimumInterval = "00:00:05")
private <T> void bulkSave(List<T> generals, CosmosRepository<T, String> repository) {
int bulkSize = 500;
for (int i = 0; i < generals.size(); i += bulkSize) {
int endIndex = Math.min(i + bulkSize, generals.size());
List<T> bulk = generals.subList(i, endIndex);
repository.saveAll(bulk);
}
int bulkSize = 500;
for (int i = 0; i < generals.size(); i += bulkSize) {
int endIndex = Math.min(i + bulkSize, generals.size());
List<T> bulk = generals.subList(i, endIndex);
repository.saveAll(bulk);
}
}
}

0 comments on commit f98cb08

Please sign in to comment.