Skip to content

Commit

Permalink
added offset and limit to not notified massive recover. Removed old l…
Browse files Browse the repository at this point in the history
…ogic
  • Loading branch information
giomella committed Dec 19, 2023
1 parent cd1ad54 commit 65cfc25
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 43 deletions.
2 changes: 1 addition & 1 deletion helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -218,10 +221,11 @@ public Iterable<FeedResponse<Receipt>> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -29,7 +27,6 @@ public static Receipt restoreReceipt(Receipt receipt) {
public static List<Receipt> receiptMassiveRestore(ReceiptStatusType statusType, ReceiptCosmosService receiptCosmosService) {
List<Receipt> receiptList = new ArrayList<>();
String continuationToken = null;
int totalPages = 0;
do {
Iterable<FeedResponse<Receipt>> feedResponseIterator =
receiptCosmosService.getNotNotifiedReceiptByStatus(continuationToken, 100, statusType);
Expand All @@ -41,8 +38,7 @@ public static List<Receipt> receiptMassiveRestore(ReceiptStatusType statusType,
}
continuationToken = page.getContinuationToken();
}
totalPages++;
} while (continuationToken != null && totalPages < IO_ERROR_TO_NOTIFY_MASSIVE_RECOVER_MAX_PAGES);
} while (continuationToken != null);
return receiptList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HttpResponseMessage.Builder>) 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())
Expand Down

0 comments on commit 65cfc25

Please sign in to comment.