diff --git a/README.md b/README.md index 9df5b5f..74cf948 100644 --- a/README.md +++ b/README.md @@ -79,40 +79,42 @@ On terminal type: then replace env variables with correct values (if there is NO default value, the variable HAS to be defined) -| VARIABLE | USAGE | DEFAULT VALUE | -|---------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------|:------------------------------------------------------:| -| `RECEIPTS_STORAGE_CONN_STRING` | Connection string to the Receipt Queue | | -| `RECEIPT_QUEUE_TOPIC` | Topic name of the Receipt Queue | | -| `COSMOS_BIZ_EVENT_CONN_STRING` | Connection string to the BizEvent CosmosDB | | -| `COSMOS_BIZ_EVENT_SERVICE_ENDPOINT` | Endpoint to the BizEvent CosmosDB | | -| `COSMOS_BIZ_EVENT_DB_NAME` | Database name of the BizEvent database in CosmosDB | | -| `COSMOS_BIZ_EVENT_CONTAINER_NAME` | Container name of the BizEvent container in CosmosDB | | -| `COSMOS_RECEIPTS_CONN_STRING` | Connection string to the Receipt CosmosDB | | -| `COSMOS_RECEIPT_SERVICE_ENDPOINT` | Endpoint to the Receipt CosmosDB | | -| `COSMOS_RECEIPT_KEY` | Key to the Receipt CosmosDB | | -| `COSMOS_RECEIPT_DB_NAME` | Database name of the Receipt database in CosmosDB | | -| `COSMOS_RECEIPT_CONTAINER_NAME` | Container name of the Receipt container in CosmosDB | | -| `COSMOS_RECEIPT_ERROR_CONTAINER_NAME` | Container name of the Receipt-message-error container in CosmosDB | | -| `BLOB_STORAGE_ACCOUNT_ENDPOINT` | Endpoint to the Receipt Blob Storage | | -| `BLOB_STORAGE_CONTAINER_NAME` | Container name of the Blob Storage containing the pdf attachments | | -| `BLOB_STORAGE_DOWNLOAD_TIMEOUT` | Timeout for the call to retrieve the attachment from the blob storage | 10 | -| `BLOB_STORAGE_DOWNLOAD_MAX_RETRY` | Max number of retry for the call to retrieve the attachment from the blob storage | 5 | -| `PDV_TOKENIZER_BASE_PATH` | PDV Tokenizer API base path | "https://api.uat.tokenizer.pdv.pagopa.it/tokenizer/v1" | -| `PDV_TOKENIZER_SEARCH_TOKEN_ENDPOINT` | PDV Tokenizer API search token endpoint | "/tokens/search" | -| `PDV_TOKENIZER_FIND_PII_ENDPOINT` | PDV Tokenizer API find pii endpoint | "/tokens/%s/pii" | -| `PDV_TOKENIZER_CREATE_TOKEN_ENDPOINT` | PDV Tokenizer API create token endpoint | "/tokens" | -| `PDV_TOKENIZER_SUBSCRIPTION_KEY` | API azure ocp apim subscription key | | -| `PDV_TOKENIZER_INITIAL_INTERVAL` | PDV Tokenizer initial interval for retry a request that fail with 429 status code | 200 | -| `PDV_TOKENIZER_MULTIPLIER` | PDV Tokenizer interval multiplier for subsequent request retry | 2.0 | -| `PDV_TOKENIZER_RANDOMIZATION_FACTOR` | PDV Tokenizer randomization factor for interval retry calculation | 0.6 | -| `PDV_TOKENIZER_MAX_RETRIES` | PDV Tokenizer max request retry | 3 | -| `TOKENIZER_APIM_HEADER_KEY` | Tokenizer APIM header key | x-api-key | -| `MAX_DATE_DIFF_MILLIS` | Difference in millis between the current time and the date from witch the
receipts will be fetched in massive recover operation | 360000 | -| `MAX_DATE_DIFF_NOTIFY_MILLIS` | Difference in millis between the current time and the date from witch the
receipts to notify will be fetched in massive recover operation | 360000 | -| `RECOVER_FAILED_CRON` | CRON expression for timer trigger function that recover failed receipt | | -| `TRIGGER_GEN_SCHEDULE` | CRON expression for timer trigger function that recover nor notified generater receipt | | +| VARIABLE | USAGE | DEFAULT VALUE | +|---------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|:------------------------------------------------------:| +| `RECEIPTS_STORAGE_CONN_STRING` | Connection string to the Receipt Queue | | +| `RECEIPT_QUEUE_TOPIC` | Topic name of the Receipt Queue | | +| `COSMOS_BIZ_EVENT_CONN_STRING` | Connection string to the BizEvent CosmosDB | | +| `COSMOS_BIZ_EVENT_SERVICE_ENDPOINT` | Endpoint to the BizEvent CosmosDB | | +| `COSMOS_BIZ_EVENT_DB_NAME` | Database name of the BizEvent database in CosmosDB | | +| `COSMOS_BIZ_EVENT_CONTAINER_NAME` | Container name of the BizEvent container in CosmosDB | | +| `COSMOS_RECEIPTS_CONN_STRING` | Connection string to the Receipt CosmosDB | | +| `COSMOS_RECEIPT_SERVICE_ENDPOINT` | Endpoint to the Receipt CosmosDB | | +| `COSMOS_RECEIPT_KEY` | Key to the Receipt CosmosDB | | +| `COSMOS_RECEIPT_DB_NAME` | Database name of the Receipt database in CosmosDB | | +| `COSMOS_RECEIPT_CONTAINER_NAME` | Container name of the Receipt container in CosmosDB | | +| `COSMOS_RECEIPT_ERROR_CONTAINER_NAME` | Container name of the Receipt-message-error container in CosmosDB | | +| `BLOB_STORAGE_ACCOUNT_ENDPOINT` | Endpoint to the Receipt Blob Storage | | +| `BLOB_STORAGE_CONTAINER_NAME` | Container name of the Blob Storage containing the pdf attachments | | +| `BLOB_STORAGE_DOWNLOAD_TIMEOUT` | Timeout for the call to retrieve the attachment from the blob storage | 10 | +| `BLOB_STORAGE_DOWNLOAD_MAX_RETRY` | Max number of retry for the call to retrieve the attachment from the blob storage | 5 | +| `PDV_TOKENIZER_BASE_PATH` | PDV Tokenizer API base path | "https://api.uat.tokenizer.pdv.pagopa.it/tokenizer/v1" | +| `PDV_TOKENIZER_SEARCH_TOKEN_ENDPOINT` | PDV Tokenizer API search token endpoint | "/tokens/search" | +| `PDV_TOKENIZER_FIND_PII_ENDPOINT` | PDV Tokenizer API find pii endpoint | "/tokens/%s/pii" | +| `PDV_TOKENIZER_CREATE_TOKEN_ENDPOINT` | PDV Tokenizer API create token endpoint | "/tokens" | +| `PDV_TOKENIZER_SUBSCRIPTION_KEY` | API azure ocp apim subscription key | | +| `PDV_TOKENIZER_INITIAL_INTERVAL` | PDV Tokenizer initial interval for retry a request that fail with 429 status code | 200 | +| `PDV_TOKENIZER_MULTIPLIER` | PDV Tokenizer interval multiplier for subsequent request retry | 2.0 | +| `PDV_TOKENIZER_RANDOMIZATION_FACTOR` | PDV Tokenizer randomization factor for interval retry calculation | 0.6 | +| `PDV_TOKENIZER_MAX_RETRIES` | PDV Tokenizer max request retry | 3 | +| `TOKENIZER_APIM_HEADER_KEY` | Tokenizer APIM header key | x-api-key | +| `MAX_DATE_DIFF_MILLIS` | Difference in millis between the current time and the date from witch the
receipts will be fetched in massive recover operation | 360000 | +| `MAX_DATE_DIFF_NOTIFY_MILLIS` | Difference in millis between the current time and the date from witch the
receipts will be fetched in massive recover operation on notification | 360000 | +| `RECOVER_FAILED_CRON` | CRON expression for timer trigger function that recover failed receipt | | +| `TRIGGER_NOTIFY_REC_SCHEDULE` | CRON expression for timer trigger function that recover not notifier receipt | | +| `RECOVER_FAILED_MASSIVE_MAX_DAYS` | Number of days in addition to the current one to executed failed recovery | 0 | +| `RECOVER_NOT_NOTIFIED_MASSIVE_MAX_DAYS` | Number of days in addition to the current one to executed not notified recovery | 0 | | `AES_SECRET_KEY` | AES encryption secret key | | -| `AES_SALT` | AES encryption salt | | +| `AES_SALT` | AES encryption salt | > to doc details about AZ fn config > see [here](https://stackoverflow.com/questions/62669672/azure-functions-what-is-the-purpose-of-having-host-json-and-local-settings-jso) diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 87575d9..a104e54 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -114,6 +114,8 @@ microservice-chart: AZURE_FUNCTIONS_MESH_JAVA_OPTS: "-javaagent:/home/site/wwwroot/jmx_prometheus_javaagent-0.19.0.jar=12345:/home/site/wwwroot/config.yaml -javaagent:/home/site/wwwroot/opentelemetry-javaagent.jar -Xmx768m -XX:+UseG1GC" FAILED_AUTORECOVER_ENABLED: "true" NOT_NOTIFIED_AUTORECOVER_ENABLED: "true" + RECOVER_FAILED_MASSIVE_MAX_DAYS: "0" + RECOVER_NOT_NOTIFIED_MASSIVE_MAX_DAYS: "0" envConfigMapExternals: template-maps: BRAND_LOGO_MAP: brand-logo-map diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index 0e780b8..a975ec1 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -114,6 +114,8 @@ microservice-chart: AZURE_FUNCTIONS_MESH_JAVA_OPTS: "-javaagent:/home/site/wwwroot/jmx_prometheus_javaagent-0.19.0.jar=12345:/home/site/wwwroot/config.yaml -javaagent:/home/site/wwwroot/opentelemetry-javaagent.jar -Xmx768m -XX:+UseG1GC" FAILED_AUTORECOVER_ENABLED: "false" NOT_NOTIFIED_AUTORECOVER_ENABLED: "false" + RECOVER_FAILED_MASSIVE_MAX_DAYS: "0" + RECOVER_NOT_NOTIFIED_MASSIVE_MAX_DAYS: "0" envConfigMapExternals: template-maps: BRAND_LOGO_MAP: brand-logo-map diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index 155bb30..9bf2bed 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -114,6 +114,8 @@ microservice-chart: AZURE_FUNCTIONS_MESH_JAVA_OPTS: "-javaagent:/home/site/wwwroot/jmx_prometheus_javaagent-0.19.0.jar=12345:/home/site/wwwroot/config.yaml -javaagent:/home/site/wwwroot/opentelemetry-javaagent.jar -Xmx768m -XX:+UseG1GC" FAILED_AUTORECOVER_ENABLED: "true" NOT_NOTIFIED_AUTORECOVER_ENABLED: "true" + RECOVER_FAILED_MASSIVE_MAX_DAYS: "0" + RECOVER_NOT_NOTIFIED_MASSIVE_MAX_DAYS: "0" envConfigMapExternals: template-maps: BRAND_LOGO_MAP: brand-logo-map diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverNotNotifiedReceiptScheduled.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverNotNotifiedReceiptScheduled.java index 893d8c8..3a23b09 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverNotNotifiedReceiptScheduled.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverNotNotifiedReceiptScheduled.java @@ -47,7 +47,7 @@ public RecoverNotNotifiedReceiptScheduled() { public void processRecoverNotNotifiedScheduledTrigger( @TimerTrigger( name = "timerInfo", - schedule = "%TRIGGER_GEN_SCHEDULE%" + schedule = "%TRIGGER_NOTIFY_REC_SCHEDULE%" ) String timerInfo, @CosmosDBOutput( 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 b3ae0a1..7c3f269 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 @@ -16,6 +16,7 @@ import it.gov.pagopa.receipt.pdf.helpdesk.exception.ReceiptNotFoundException; import java.time.OffsetDateTime; +import java.time.temporal.ChronoUnit; /** * Client for the CosmosDB database @@ -32,6 +33,10 @@ public class ReceiptCosmosClientImpl implements ReceiptCosmosClient { private final String millisDiff = System.getenv("MAX_DATE_DIFF_MILLIS"); private final String millisNotifyDif = System.getenv("MAX_DATE_DIFF_NOTIFY_MILLIS"); + private final String numDaysRecoverFailed = System.getenv().getOrDefault("RECOVER_FAILED_MASSIVE_MAX_DAYS", "0"); + + private final String numDaysRecoverNotNotified = System.getenv().getOrDefault("RECOVER_NOT_NOTIFIED_MASSIVE_MAX_DAYS", "0"); + private final CosmosClient cosmosClient; private ReceiptCosmosClientImpl() { @@ -88,8 +93,10 @@ public Iterable> getFailedReceiptDocuments(String continua CosmosContainer cosmosContainer = cosmosDatabase.getContainer(containerId); //Build query - String query = String.format("SELECT * FROM c WHERE c.status = '%s' or c.status = '%s'", - ReceiptStatusType.FAILED, ReceiptStatusType.NOT_QUEUE_SENT); + String query = String.format("SELECT * FROM c WHERE (c.status = '%s' or c.status = '%s') AND c.inserted_at >= %s", + ReceiptStatusType.FAILED, ReceiptStatusType.NOT_QUEUE_SENT, + OffsetDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays( + Long.parseLong(numDaysRecoverFailed)).toInstant().toEpochMilli()); //Query the container return cosmosContainer @@ -106,8 +113,12 @@ public Iterable> getInsertedReceiptDocuments(String contin CosmosContainer cosmosContainer = cosmosDatabase.getContainer(containerId); //Build query - String query = String.format("SELECT * FROM c WHERE (c.status = '%s' AND ( %s - c.inserted_at) >= %s)", - ReceiptStatusType.INSERTED, OffsetDateTime.now().toInstant().toEpochMilli(), millisDiff); + String query = String.format("SELECT * FROM c WHERE (c.status = '%s' AND c.inserted_at >= %s " + + "AND ( %s - c.inserted_at) >= %s)", + ReceiptStatusType.INSERTED, + OffsetDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays( + Long.parseLong(numDaysRecoverFailed)).toInstant().toEpochMilli(), + OffsetDateTime.now().toInstant().toEpochMilli(), millisDiff); //Query the container return cosmosContainer @@ -186,8 +197,11 @@ public Iterable> getGeneratedReceiptDocuments(String conti CosmosContainer cosmosContainer = cosmosDatabase.getContainer(containerId); //Build query - String query = String.format("SELECT * FROM c WHERE (c.status = '%s' AND ( %s - c.generated_at) >= %s)", - ReceiptStatusType.GENERATED, OffsetDateTime.now().toInstant().toEpochMilli(), millisNotifyDif); + String query = String.format("SELECT * FROM c WHERE (c.status = '%s' AND c.generated_at >= %s AND ( %s - c.generated_at) >= %s)", + ReceiptStatusType.GENERATED, + OffsetDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays( + Long.parseLong(numDaysRecoverNotNotified)).toInstant().toEpochMilli(), + OffsetDateTime.now().toInstant().toEpochMilli(), millisNotifyDif); //Query the container return cosmosContainer @@ -204,7 +218,11 @@ public Iterable> getIOErrorToNotifyReceiptDocuments(String CosmosContainer cosmosContainer = cosmosDatabase.getContainer(containerId); //Build query - String query = String.format("SELECT * FROM c WHERE c.status = '%s'", ReceiptStatusType.IO_ERROR_TO_NOTIFY); + String query = String.format("SELECT * FROM c WHERE c.status = '%s' AND c.generated_at >= %s", + ReceiptStatusType.IO_ERROR_TO_NOTIFY, + OffsetDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays( + Long.parseLong(numDaysRecoverNotNotified)).toInstant().toEpochMilli() + ); //Query the container return cosmosContainer