I am trying to do:
- pull 50 rows from third party API
- create payloads for issues
- create issues (bulk)
- back to step 1. until I pulled all rows from third party API.
Code:
/**
* Create Jira Issues
*
* @param configuration
* @param assetType
* @param allIds
* @param findingsOffset
*/
export const createJiraIssue = async (configuration: IntegrationConfiguration, assetType: string, allIds: any, findingsOffset: number) => {
//HERE I AM GETTING 50 rows from third party API
const findings: any = await getAllFindings(configuration.assets, 'open', assetType, findingsOffset);
const custom_field: string = await storage.get('whvid_custom_field_id');
let jiraIssuePayloads : any = {"issueUpdates": []};
for (const item of findings.collection) {
const i = findings.collection.indexOf(item);
//Check if we can create the Jira issue
if (!allIds.includes(item.id.toString()) && await isVulnerabilityAllowedToCreate(item)) {
//create payloads for issues
}
//CREATE issues bulk
await createIssues(jiraIssuePayloads);
jiraIssuePayloads = null;
//here I am calling same function but with new offset
if (findings['offset'] > 0) {
await createJiraIssue(configuration, assetType, allIds, findings['offset']);
}
}
Third party API call:
export const getAllFindings = async (assets: [], status: string, assetType: string, startOffset: number) => {
const findings = await getFindingByAssetIdAndAssetType(assets, status, assetType, startOffset.toString());
if(findings.page.totalPage !== findings.page.currentPage){
findings.offset = startOffset + limit.FINDINGS;
}
return findings;
}
My app usually stop working after 18th call. With no error no logs anything. I am very new to JS, so maybe problem is async functions. Any idea what can be problem?
Thank you