From 12be0f5c44acb53c50b8284528c2d25a16464bed Mon Sep 17 00:00:00 2001 From: svariant Date: Mon, 13 Nov 2023 16:38:53 +0100 Subject: [PATCH 1/2] [chore] Prod test script --- .../src/scripts/prod_test_script.js | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 performance-test/src/scripts/prod_test_script.js diff --git a/performance-test/src/scripts/prod_test_script.js b/performance-test/src/scripts/prod_test_script.js new file mode 100644 index 00000000..bf60064f --- /dev/null +++ b/performance-test/src/scripts/prod_test_script.js @@ -0,0 +1,67 @@ +import { CosmosClient } from '@azure/cosmos'; + +//ENVIRONMENTAL VARIABLES +const bizEventCosmosDBConnString = ""; //bizEvent cosmos connection string +const bizEventDatabaseID = "db"; +const bizEventContainerID = "biz-events"; + +const receiptCosmosDBConnString = ""; //receipt cosmos connection string +const receiptDatabaseID = "db"; +const receiptContainerID = "receipts"; + +const apiRetryFailedURI = ""; //Retry failed function apim uri +const ocpApimKey = ""; //APIM ocp key + +//CLIENTS +const bizeventClient = new CosmosClient(bizEventCosmosDBConnString); +const bizeventContainer = bizeventClient.database(bizEventDatabaseID).container(bizEventContainerID); + +const receiptClient = new CosmosClient(receiptCosmosDBConnString); +const receiptContainer = receiptClient.database(receiptDatabaseID).container(receiptContainerID); + +//INPUTS +const minDate = new Date("04/01/2023").getTime(); //mm/dd/yyyy +const FISCAL_CODES_TO_TEST = [ + "" +]; + +const updateBizEvents = async () => { + for (const fiscalCode of FISCAL_CODES_TO_TEST) { + let { resources } = await bizeventContainer.items.query({ + query: "SELECT * from c WHERE c.debtor.entityUniqueIdentifierValue = @fiscalCode and c.timestamp >= @minDate and c.eventStatus = 'DONE'", + parameters: [{ name: "@fiscalCode", value: fiscalCode }, { name: "@minDate", value: minDate }] + }).fetchAll(); + + for (let j = 0; j < resources.length; j++) { + let bizEvent = resources[j]; + + let exist = await bizeventContainer.item(bizEvent.id, bizEvent.id).read(); + + if (exist.statusCode === 200) { + let receipt = { + eventId: bizEvent.id, + status: "FAILED" + }; + let { resource } = await receiptContainer.items.create(receipt); + console.log("SAVED receipt with id: " + resource.id); + + fetch(apiRetryFailedURI, { + method: "PUT", + headers: { + 'Content-Type': 'application/json', + "Ocp-Apim-Key": ocpApimKey + }, + body: { + "eventId": bizEvent.id + } + }) + .then(() => console.log("RETRIED receipt with id: " + resource.id)) + .catch(() => console.log("FAILED RETRY for receipt with id: " + resource.id)) + } + + } + + } +} + +updateBizEvents(); \ No newline at end of file From 018881e13c4c42ca27efce779dc6de4d24ea29c3 Mon Sep 17 00:00:00 2001 From: svariant Date: Mon, 13 Nov 2023 16:39:50 +0100 Subject: [PATCH 2/2] [chore] Changed ocp apim header key --- performance-test/src/scripts/prod_test_script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/performance-test/src/scripts/prod_test_script.js b/performance-test/src/scripts/prod_test_script.js index bf60064f..d4b9206b 100644 --- a/performance-test/src/scripts/prod_test_script.js +++ b/performance-test/src/scripts/prod_test_script.js @@ -49,7 +49,7 @@ const updateBizEvents = async () => { method: "PUT", headers: { 'Content-Type': 'application/json', - "Ocp-Apim-Key": ocpApimKey + "Ocp-Apim-Subscription-Key": ocpApimKey }, body: { "eventId": bizEvent.id