From 65cfc25080b65410384720634068ae6cec748479 Mon Sep 17 00:00:00 2001 From: giomella Date: Tue, 19 Dec 2023 09:38:30 +0100 Subject: [PATCH] added offset and limit to not notified massive recover. Removed old logic --- helm/values-dev.yaml | 2 +- helm/values-prod.yaml | 2 +- helm/values-uat.yaml | 2 +- .../client/impl/ReceiptCosmosClientImpl.java | 8 +++-- .../utils/RecoverNotNotifiedReceiptUtils.java | 6 +--- .../RecoverNotNotifiedReceiptMassiveTest.java | 33 ------------------- 6 files changed, 10 insertions(+), 43 deletions(-) diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 0ab3102..e9f7ded 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -116,7 +116,7 @@ microservice-chart: NOT_NOTIFIED_AUTORECOVER_ENABLED: "true" RECOVER_FAILED_MASSIVE_MAX_DAYS: "0" RECOVER_NOT_NOTIFIED_MASSIVE_MAX_DAYS: "0" - IO_ERROR_TO_NOTIFY_MASSIVE_RECOVER_MAX_PAGES: "2" + RECOVER_NOT_NOTIFIED_MASSIVE_MAX_RECORDS: "200" envConfigMapExternals: template-maps: BRAND_LOGO_MAP: brand-logo-map diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index e96349d..e73449b 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -116,7 +116,7 @@ microservice-chart: NOT_NOTIFIED_AUTORECOVER_ENABLED: "true" RECOVER_FAILED_MASSIVE_MAX_DAYS: "0" RECOVER_NOT_NOTIFIED_MASSIVE_MAX_DAYS: "0" - IO_ERROR_TO_NOTIFY_MASSIVE_RECOVER_MAX_PAGES: "2" + RECOVER_NOT_NOTIFIED_MASSIVE_MAX_RECORDS: "200" envConfigMapExternals: template-maps: BRAND_LOGO_MAP: brand-logo-map diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index a9584eb..c2e43bf 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -116,7 +116,7 @@ microservice-chart: NOT_NOTIFIED_AUTORECOVER_ENABLED: "true" RECOVER_FAILED_MASSIVE_MAX_DAYS: "0" RECOVER_NOT_NOTIFIED_MASSIVE_MAX_DAYS: "0" - IO_ERROR_TO_NOTIFY_MASSIVE_RECOVER_MAX_PAGES: "2" + RECOVER_NOT_NOTIFIED_MASSIVE_MAX_RECORDS: "200" envConfigMapExternals: template-maps: BRAND_LOGO_MAP: brand-logo-map diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java index 7c3f269..527ba7d 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java @@ -37,6 +37,9 @@ public class ReceiptCosmosClientImpl implements ReceiptCosmosClient { private final String numDaysRecoverNotNotified = System.getenv().getOrDefault("RECOVER_NOT_NOTIFIED_MASSIVE_MAX_DAYS", "0"); + private final int recordsLimitRecoverNotNotified = Integer.parseInt(System.getenv().getOrDefault("RECOVER_NOT_NOTIFIED_MASSIVE_MAX_RECORDS", "200")); + + private final CosmosClient cosmosClient; private ReceiptCosmosClientImpl() { @@ -218,10 +221,11 @@ public Iterable> getIOErrorToNotifyReceiptDocuments(String CosmosContainer cosmosContainer = cosmosDatabase.getContainer(containerId); //Build query - String query = String.format("SELECT * FROM c WHERE c.status = '%s' AND c.generated_at >= %s", + String query = String.format("SELECT * FROM c WHERE c.status = '%s' AND c.generated_at >= %s OFFSET 0 LIMIT %s", ReceiptStatusType.IO_ERROR_TO_NOTIFY, OffsetDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays( - Long.parseLong(numDaysRecoverNotNotified)).toInstant().toEpochMilli() + Long.parseLong(numDaysRecoverNotNotified)).toInstant().toEpochMilli(), + recordsLimitRecoverNotNotified ); //Query the container diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/RecoverNotNotifiedReceiptUtils.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/RecoverNotNotifiedReceiptUtils.java index e56dd7f..f3b841b 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/RecoverNotNotifiedReceiptUtils.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/RecoverNotNotifiedReceiptUtils.java @@ -10,8 +10,6 @@ public class RecoverNotNotifiedReceiptUtils { - private static final int IO_ERROR_TO_NOTIFY_MASSIVE_RECOVER_MAX_PAGES = Integer.parseInt(System.getenv().getOrDefault("IO_ERROR_TO_NOTIFY_MASSIVE_RECOVER_MAX_PAGES", "2")); - public static Receipt restoreReceipt(Receipt receipt) { receipt.setStatus(ReceiptStatusType.GENERATED); receipt.setNotificationNumRetry(0); @@ -29,7 +27,6 @@ public static Receipt restoreReceipt(Receipt receipt) { public static List receiptMassiveRestore(ReceiptStatusType statusType, ReceiptCosmosService receiptCosmosService) { List receiptList = new ArrayList<>(); String continuationToken = null; - int totalPages = 0; do { Iterable> feedResponseIterator = receiptCosmosService.getNotNotifiedReceiptByStatus(continuationToken, 100, statusType); @@ -41,8 +38,7 @@ public static List receiptMassiveRestore(ReceiptStatusType statusType, } continuationToken = page.getContinuationToken(); } - totalPages++; - } while (continuationToken != null && totalPages < IO_ERROR_TO_NOTIFY_MASSIVE_RECOVER_MAX_PAGES); + } while (continuationToken != null); return receiptList; } diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverNotNotifiedReceiptMassiveTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverNotNotifiedReceiptMassiveTest.java index 3d8d899..decc107 100644 --- a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverNotNotifiedReceiptMassiveTest.java +++ b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverNotNotifiedReceiptMassiveTest.java @@ -115,39 +115,6 @@ void recoverNotNotifiedReceiptMassiveForIOErrorToNotifySuccess() { assertNull(captured2.getReasonErrPayer()); } - @Test - void recoverNotNotifiedReceiptMassiveForIOErrorToNotifySuccessWithMoreThan10Pages() { - when(requestMock.getQueryParameters()) - .thenReturn(Collections.singletonMap("status", ReceiptStatusType.IO_ERROR_TO_NOTIFY.name())); - - FeedResponse feedResponseMock = mock(FeedResponse.class); - when(feedResponseMock.getResults()) - .thenReturn(Collections.singletonList(buildReceipt(ReceiptStatusType.IO_ERROR_TO_NOTIFY))); - when(feedResponseMock.getContinuationToken()).thenReturn("token", "token"); - when(receiptCosmosServiceMock.getNotNotifiedReceiptByStatus(any(), any(), any())) - .thenReturn(Collections.singletonList(feedResponseMock), - Collections.singletonList(feedResponseMock), - Collections.singletonList(feedResponseMock), - Collections.singletonList(feedResponseMock)); - - doAnswer((Answer) invocation -> { - HttpStatus status = (HttpStatus) invocation.getArguments()[0]; - return new HttpResponseMessageMock.HttpResponseMessageBuilderMock().status(status); - }).when(requestMock).createResponseBuilder(any(HttpStatus.class)); - - // test execution - HttpResponseMessage response = sut.run(requestMock, documentReceipts, executionContextMock); - - // test assertion - assertNotNull(response); - assertEquals(HttpStatus.OK, response.getStatus()); - assertNotNull(response.getBody()); - - verify(documentReceipts).setValue(receiptCaptor.capture()); - - assertEquals(2, receiptCaptor.getValue().size()); - } - @Test void recoverNotNotifiedReceiptMassiveForGeneratedSuccess() { when(requestMock.getQueryParameters())