I’m looking for a way to implement a while loop in server connect.
Without any luck so far…
Use case : I need to produce OHLC data from trades history.
So the script should run until all history has been exhausted and formated into OHLC data for every hour of trade.
(+ in case of script timeout, work is resumed where it stops…)
It seems like the repeater only accepts integer values and not boolean expressions ?
I tried several variants of the following repeat expression :
The repeat expression provided in my previous screenshot would give 4 loops :
I tried several variant of the boolean expression (without curly braces, true directly, etc…)
My loop goes from 1 to 21 iterations maximum.
My best workaround so far would be something silly like 99999999 as a condition.
But I don’t event know :
how to exit the loop in that instance.
what’s the max integer I can input in here.
Thank you very much for your help and have a great evening !
P.S. By the way, I’m wondering if I’m the only one who feels like a “manual for coders converting to wappler” would be very much needed ? Like a topic where we could centralise all those “little things” we are used to do in 2 minutes with code but are counter-intuitive or just not so obvious to do in Wappler.
bool hasMoreHistory = true;
while (hasMoreHistory){
// Do we have enough history to process ?
if ( ! loadHistory() ){
// If there is no more history to process, exit loop
hasMoreHistory = false;
}else{
// if there is, process data
formatOHLCdata();
}
}
Yes, i am guessing you are trying to use what is effectively a FOR loop as a DO WHILE and i don’t think that will work as I am not sure the repeat condition is re-evaluated after initialisation.
Not tried this but perhaps calling the server action recursively based on the condition may be a way to go, you may be able to do this via the Core Actions->Redirect to re-call the server action within a Conditional statement. I have to add I have never tried this, perhaps @Teodor may know if this can be done.
Alternatively, if this is effectively a housekeeping action, a method I have used is to run it on a single record but from a server scheduler (cron job) on a regular basis but this would depend on the number of iterations required and how time critical everything is
It’s a database record (in that case) but…
I need the condition to be evaluated at each iteration as we have another process loading data through CRON while this one will format it.
So the number of records has to be checked inside each iteration to know when to stop execution.
I think the issue is he is trying to use a variable as the repeat condition, not a data query
So he sets a variable called “HasMoreHistory” to true initially (so repeat will be infinite)
He then changes the value of “HasMoreHistory” dynamically within the repeat in the hope that this will effectively exit the repeat due to the condition change
So he is trying to do this (pseudocode) :
HasMoreHistory = true
do while HasMoreHistory
if ‘condition is not satisified’ then HasMoreHistory = False // exit loop
while end
My intention is to run the process through cron at a regular interval but I have millions of rows to process so I obviously need a way to loop inside the script and not just relying on multiplying cron executions !
I’ll look into “re-calling” the server action, didn’t think about this.
Performance wise though, will that open and close DB connections each time ?
Would be useful Teodor as I actually has the same issue last week, fortunately I was able to resolve it as i said above, single action called every 5 mins via cron job but that was only possible because numbers were low
We are currently checking the best way to integrate while, do…while and switch/case within server connect UI so they are available as steps there
Will keep you updated about this.