Skip to content

Commit

Permalink
[SELC-4847] Added check if retryable exception
Browse files Browse the repository at this point in the history
  • Loading branch information
flaminiaScarciofolo committed May 31, 2024
1 parent 3018135 commit 759762f
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import it.pagopa.selfcare.user.util.UserUtils;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Response;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -20,6 +21,7 @@

import java.time.Duration;
import java.util.*;
import java.util.concurrent.TimeoutException;

import org.openapi.quarkus.user_registry_json.api.UserApi;
import org.openapi.quarkus.user_registry_json.model.*;
Expand Down Expand Up @@ -55,25 +57,35 @@ public class UserRegistryServiceImpl implements UserRegistryService {
@Override
public Uni<UserResource> findByIdUsingGET(String fl, String id) {
return userRegistryApi.findByIdUsingGET(fl, id)
.onFailure().retry().withBackOff(Duration.ofSeconds(retryMinBackOff), Duration.ofHours(retryMaxBackOff)).atMost(maxRetry);
.onFailure(this::checkIfIsRetryableException)
.retry().withBackOff(Duration.ofSeconds(retryMinBackOff), Duration.ofSeconds(retryMaxBackOff)).atMost(maxRetry);

}

@Override
public Uni<UserId> saveUsingPATCH(SaveUserDto saveUserDto) {
return userRegistryApi.saveUsingPATCH(saveUserDto)
.onFailure().retry().withBackOff(Duration.ofSeconds(retryMinBackOff), Duration.ofHours(retryMaxBackOff)).atMost(maxRetry);
.onFailure(this::checkIfIsRetryableException)
.retry().withBackOff(Duration.ofSeconds(retryMinBackOff), Duration.ofSeconds(retryMaxBackOff)).atMost(maxRetry);
}

@Override
public Uni<UserResource> searchUsingPOST(String fl, UserSearchDto userSearchDto) {
return userRegistryApi.searchUsingPOST(fl, userSearchDto)
.onFailure().retry().withBackOff(Duration.ofSeconds(retryMinBackOff), Duration.ofHours(retryMaxBackOff)).atMost(maxRetry);
.onFailure(this::checkIfIsRetryableException)
.retry().withBackOff(Duration.ofSeconds(retryMinBackOff), Duration.ofSeconds(retryMaxBackOff)).atMost(maxRetry);
}

@Override
public Uni<Response> updateUsingPATCH(String id, MutableUserFieldsDto mutableUserFieldsDto) {
return userRegistryApi.updateUsingPATCH(id, mutableUserFieldsDto)
.onFailure().retry().withBackOff(Duration.ofSeconds(retryMinBackOff), Duration.ofHours(retryMaxBackOff)).atMost(maxRetry);
.onFailure(this::checkIfIsRetryableException)
.retry().withBackOff(Duration.ofSeconds(retryMinBackOff), Duration.ofSeconds(retryMaxBackOff)).atMost(maxRetry);
}

private boolean checkIfIsRetryableException(Throwable throwable) {
return throwable instanceof TimeoutException ||
(throwable instanceof WebApplicationException webApplicationException && webApplicationException.getResponse().getStatus() == 429);
}


Expand Down
6 changes: 3 additions & 3 deletions apps/user-ms/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ user-ms.aws.ses.region=${AWS_SES_REGION:eu-south-1}

quarkus.smallrye-openapi.store-schema-directory=src/main/docs

user-ms.retry.min-backoff=${USER-MS-RETRY-MIN-BACKOFF:10}
user-ms.retry.max-backoff=${USER-MS-RETRY-MAX-BACKOFF:12}
user-ms.retry=${USER-MS-RETRY:3}
user-ms.retry.min-backoff=${USER_MS_RETRY_MIN_BACKOFF:5}
user-ms.retry.max-backoff=${USER_MS_RETRY_MAX_BACKOFF:60}
user-ms.retry=${USER_MS_RETRY:3}
10 changes: 5 additions & 5 deletions infra/container_apps/user-ms/env/dev-pnpg/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ app_settings = [
value = "string"
},
{
name = "USER-MS-RETRY-MIN-BACKOFF"
value = 10
name = "USER_MS_RETRY_MIN_BACKOFF"
value = 5
},
{
name = "USER-MS-RETRY-MAX-BACKOFF"
value = 12
name = "USER_MS_RETRY_MAX_BACKOFF"
value = 60
},
{
name = "USER-MS-RETRY"
name = "USER_MS_RETRY"
value = 3
}
]
Expand Down
10 changes: 5 additions & 5 deletions infra/container_apps/user-ms/env/dev/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ app_settings = [
value = true
},
{
name = "USER-MS-RETRY-MIN-BACKOFF"
value = 10
name = "USER_MS_RETRY_MIN_BACKOFF"
value = 5
},
{
name = "USER-MS-RETRY-MAX-BACKOFF"
value = 12
name = "USER_MS_RETRY_MAX_BACKOFF"
value = 60
},
{
name = "USER-MS-RETRY"
name = "USER_MS_RETRY"
value = 3
}
]
Expand Down
10 changes: 5 additions & 5 deletions infra/container_apps/user-ms/env/prod-pnpg/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ app_settings = [
value = "https://api.pdv.pagopa.it/user-registry/v1"
},
{
name = "USER-MS-RETRY-MIN-BACKOFF"
value = 10
name = "USER_MS_RETRY_MIN_BACKOFF"
value = 5
},
{
name = "USER-MS-RETRY-MAX-BACKOFF"
value = 12
name = "USER_MS_RETRY_MAX_BACKOFF"
value = 60
},
{
name = "USER-MS-RETRY"
name = "USER_MS_RETRY"
value = 3
}
]
Expand Down
10 changes: 5 additions & 5 deletions infra/container_apps/user-ms/env/prod/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ app_settings = [
value = "https://selc-p-eventhub-ns.servicebus.windows.net/sc-users"
},
{
name = "USER-MS-RETRY-MIN-BACKOFF"
value = 10
name = "USER_MS_RETRY_MIN_BACKOFF"
value = 5
},
{
name = "USER-MS-RETRY-MAX-BACKOFF"
value = 12
name = "USER_MS_RETRY_MAX_BACKOFF"
value = 60
},
{
name = "USER-MS-RETRY"
name = "USER_MS_RETRY"
value = 3
}
]
Expand Down
10 changes: 5 additions & 5 deletions infra/container_apps/user-ms/env/uat-pnpg/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ app_settings = [
value = "selc-u-product"
},
{
name = "USER-MS-RETRY-MIN-BACKOFF"
value = 10
name = "USER_MS_RETRY_MIN_BACKOFF"
value = 5
},
{
name = "USER-MS-RETRY-MAX-BACKOFF"
value = 12
name = "USER_MS_RETRY_MAX_BACKOFF"
value = 60
},
{
name = "USER-MS-RETRY"
name = "USER_MS_RETRY"
value = 3
}
]
Expand Down
10 changes: 5 additions & 5 deletions infra/container_apps/user-ms/env/uat/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ app_settings = [
value = "selc-u-product"
},
{
name = "USER-MS-RETRY-MIN-BACKOFF"
value = 10
name = "USER_MS_RETRY_MIN_BACKOFF"
value = 5
},
{
name = "USER-MS-RETRY-MAX-BACKOFF"
value = 12
name = "USER_MS_RETRY_MAX_BACKOFF"
value = 60
},
{
name = "USER-MS-RETRY"
name = "USER_MS_RETRY"
value = 3
}

Expand Down

0 comments on commit 759762f

Please sign in to comment.