我的wix网站后端的代码意外停止

时间:2019-02-17 01:39:25

标签: javascript wixcode

我编写了一个异步函数,该函数应该检查给定的URL是否从get中返回“ 200”,否则请等待几秒钟以尝试有限次数。当我在使用节点的计算机上运行该代码时,该代码运行良好,但是当我将其传输到后端时,它只检查一次站点,然后在收到错误时立即停止。我在做什么错了?

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();
}

1 个答案:

答案 0 :(得分:0)

似乎后端功能可以运行多少时间是有限制的。根据Wix代码forum,该限制似乎是14秒,尽管这看起来不像Wix的官方数字。

相关问题