I have created a server action which calls an API to get data. The endpoint is paginated so I created a loop which will increment a page counter which I include in the call.

Example: google.com/api/sample?page={pageCtr}

I was redoing the function as it was not doing what I wanted but I forgot to add an Assign to increment the counter which led to an infinite loop when I called the server action.

I checked ServiceCenter Integration Logs and the endpoint was still being called.

How do I stop the server action? Or end the infinite loop?

Solution


Hi Prim,

As per what I know, the server action can only be terminated when there it's timed out or some error occurs.

looping API call is not a good idea. Specially if you are calling that on page load or on any Page action.

Suggestion

1. Limit the call to a certain number of times only if that is possible (although its not good idea)

2. Use a timer and an entity to save the data fetched from API

Call the API (run the loop ) for a particular number of times, each time your timer runs. (say 100). And run the timer in a short period. You can manually trigger the timer again if the first 100 loops are completed by using the Wake function.

Add a check to break the loop on condition like when no reply is returned from the API.(it generally means that there are no more records to add to list) 

here you will only see information on the screen when the timer ran and data is fetched.



Solution

Hi Pim,

You could try and publish a new version of your module that will fix the endless loop. 

If that does not help consider disable and then enable the application again in Service Center.

If that does not help consider restarting the services in LifeTime.

Regards,

Daniel

pranav pandey wrote:


Hi Prim,

As per what I know, the server action can only be terminated when there it's timed out or some error occurs.

looping API call is not a good idea. Specially if you are calling that on page load or on any Page action.

Suggestion

1. Limit the call to a certain number of times only if that is possible (although its not good idea)

2. Use a timer and an entity to save the data fetched from API

Call the API (run the loop ) for a particular number of times, each time your timer runs. (say 100). And run the timer in a short period. You can manually trigger the timer again if the first 100 loops are completed by using the Wake function.

Add a check to break the loop on condition like when no reply is returned from the API.(it generally means that there are no more records to add to list) 

here you will only see information on the screen when the timer ran and data is fetched.

 Hi pranav,

Will try to apply those to minimize future errors. Thanks. The api is still being called in Integrations so I don't think it will time out.

Regards,
Primus 

 

Daniël Kuhlmann wrote:

Hi Pim,

You could try and publish a new version of your module that will fix the endless loop. 

If that does not help consider disable and then enable the application again in Service Center.

If that does not help consider restarting the services in LifeTime.

Regards,

Daniel

 

 Hi Daniel,

Yes that is what I'm looking for. I already did option 1 and 2 but it did not stop the action. I could not do option 3 because the actions in the tutorial were not present in my LifeTime, I think because this is a personal environment.

I might just wait it out. 

Regards,
Primus

Hi All,

It stopped calling the api endpoint after a while.

Thanks for the suggestions.

Regards,
Primus