Scheduled event automatically stops execution before process fully completed

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?

1 Like

@Parth_Shah,
Good Day!
Can you please check if is there any error in the response of freshsalesProxy.getContatcs function ?

Thanks

@Santhosh I have checked it and also have placed console their but there is no any error.
Thank you

Can anyone please provide an update?

Thank you

Hi @Parth_Shah,
can you please share with us the logs which you have?

Currently, I don’t have that logs but I have raised this similar issue it might helpful to you to find out Process execution stopped due to timeout