I want to periodically execute a server action every 5 seconds by calling an API to fetch data. Then, based on the retrieved data, update a table. I attempted to use a timer, but the minimum interval is 1 minute, which is too long. Is there a better solution?
Thanks for your response.
Hi,
Non of the above replies give you what you need ad it would require the app to run in a browser.
You can use a long running timer, where in the timer you use the OutSystems Forge component https://www.outsystems.com/forge/component-overview/1244/sleep , to wait 5 seconds to execute the server action.
Make sure they in this loop you use a site property to be able to stop the looping of 5 seconds if needed.
Regards,
Daniel
Hi Daniel ,
If I execute like this in Process and wait for time, is it feasible?
Or will it pose any potential risks to my project?
This solution generates a lot of overhead for what you want to achieve as every activity in your process does some logging, this will flood the logs with data.
I stick to my previous suggestion.
What you're saying is very reasonable. Should we loop through sleep in timer like this?
yes the sleep action you set to 5 seconds.
But you need to extend your timer to set a timout, and end the timer after that timeout but wake it again. Else it will keep running forever.
There is several articles about this, here is one that you can use and implement:https://www.osquay.com/knowledge-center/how-to-make-sure-a-heavy-timer-doesnt-misbehave-in-the-outsystems-platform
Thank you very much, Daniel.
This has been very helpful to me.
Hi,Daniel
I would like to ask you another question again. I use timer and sleep to do this, but the service center keeps prompting [SLOWEXTENSION]. I would like to know if this will affect performance?Or is there any good way to solve this problem?
Thank you very much for your reply again,
Jim
haha that is a false positive, all the sleep action does is be idle, inherently that is recognized as a slow extension. But the whole purpose of the extension is to slow down the process, else you won't use it.
Hi @lu junfeng, may I know more on your scenario. Is that calling some API every 5 secs, retrieve data and update the data inside OutSystems Entity (Table) or update a table inside a UI screen/web block for displaying?
Hi @lu junfeng ,You can use the forge component https://www.outsystems.com/forge/component-overview/11726/auto-refresh to achieve your scenario.Please let me know if you have more queries.Regards,
I want to know more about the scenario, why want to call the api every 5 seconds. Is this API provide new data at every 5 seconds.
regards
Hi lu junfeng , may be it will help for youIf you need to call server action for every five second1. In On-ready event , Use javascript to call Client action every Five second( you can change he seconds manually as required.)"setInterval(function(){$actions.SampleClientAction()}, 5000); "2.call the server action inside the Client Action.
Thank you very much for your help, but maybe I didn't make my question clear enough.
There is a system on the outside that updates data in real time, and my OutSystems project needs to get his latest data as quickly as possible to update my OutSystems project.So I hope to perform this update operation at the level of the entire project, such as the timer, but the timer interval is too long. Instead of requesting it on the page and then updating it, because there will be many users, it will generate many requests, so that it will always link to this API and update the data table.
Thank you all for your help.
Hi Lu
I attached the OML you can go with this it will help you