I am calling a freshsales API to fetch contacts from freshsales in the scheduled event method when APP is installed. I am fetching existing records to sync with other platforms. So It might possible that there is existed contact count might be 100, 500, 1000, 12000 or anything.
Here is my code outline
async fetchFreshsalesContacts(payload) {
try {
const freshsalesProxy = new FreshsalesProxy(payload.iparams);
const viewId = payload.iparams?.freshsalesFilter?.id;
var contacts = [];
const PAGE_SIZE = 100;
var page_number = 1;
var needStop = false;
// Fetch all contacts
while (!needStop) {
// Query for fetch all contacts
let query = `per_page=${PAGE_SIZE}&page=${page_number}`;
console.log("query=====", query)
const contactResposne = await freshsalesProxy.getContatcs(
query,
viewId
);
if (
contactResposne.meta.total_pages === page_number ||
contactResposne.meta.total_pages === 0
) {
needStop = true;
}
page_number++;
contacts.push(...contactResposne.contacts);
}
return contacts;
} catch (error) {
console.log('Error:', error);
}
}
There is some other execution before this function but when this method starts execution (for fetching 5000+ contacts), it stops arround page_number 26 to 32, and No other process is also executed after this which should execute depending on this.
It does not give any error also.
Is it could affect by the timeout (20 seconds) or any other reason could be behind this?
Can anyone have any idea related to this?