Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore prod test script #95

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions performance-test/src/scripts/prod_test_script.js
Original file line number Diff line number Diff line change
@@ -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-Subscription-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();
Loading