'Code halts unexpectedly on backend of my wix site

I wrote an asynchronous function which is supposed to check if a given url returns a '200' from a get and otherwise wait a few seconds to try again a limited number of times. The code works just fine when I run it in my computer using node but when I transfer it to backend it only checks for the site once and then immediately stops when receiving an error. What am I doing wrong?

async function wait(url,delay=10000,attp=3){
 let t0 = new Date(Date.now());
 let attempts = 0;
    console.log('starting...');
 async function check(){
 if(attempts<attp){
            console.log('ATTEMPTS: ',attempts);
 return await request.get(url).on('error',
 async function(err){
                console.log('ERROR: ',err);
                attempts+=1;
 return await setTimeout(()=>{check()},delay);
            }).on('response',
 async function(response){
 if(response.statusCode===200){
 let t1 = new Date(Date.now());
                    wixData.insert('pagSeguroTimeStats', { 'time': (t1 - t0) / 1000. });
 return '200';
                }else{
                    attempts+=1;
                    console.log('not 200');
 return await setTimeout(()=>{check()},delay);
                }
            });
        }else{
 return '404';
        }
    }
 return check();
}


Solution 1:[1]

The 14 second limit only applies to web functions.

Time Wix allows web modules called from the frontend, HTTP functions, and router hooks to run for up to 14 seconds. This limitation applies to both free and premium sites. Any of these methods that take longer than 14 seconds receives a 504 response code. Note that after 14 seconds the code might still execute, but the connection to the client is closed so the results do not appear in the frontend. This error message appears in your log: /backend/.js(w)/ timed out because it exceeded the maximum execution time.

I've got a .js function that just stop, and I get no error or anything.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Paul