javascript - Retry when no response from website -
i use recursive function below, in order reopen website if httpstatus != 200
:
retryopen = function(){ this.thenopen("http://www.mywebsite.com", function(response){ utils.dump(response.status); var httpstatus = response.status; if(httpstatus != 200){ this.echo("failed website, retry"); this.then(retryopen); } else{ var thisnow = hello[variable]; this.evaluate(function(valueoptionselect){ $('select#the_id').val(valueoptionselect); $('select#the_id').trigger('change'); },thisnow); } }); }
the problem retryopen
function not go far callback function(response){}
. then, script freezes.
i wonder how 1 change function able recursively try open website again if there no response website (not error code 404 or something)? in other words, how rewrite retryopen
function reruns when function not reach callback after amount of time?
i try this. please note untested code, should on correct path
retryopen = function(maxretry){ var count = 0; function makecall(url) { this.thenopen(url, function(response){ utils.dump(response.status); }); } function openit(){ makecall.call(this,"http://www.mywebsite.com"); this.waitfor(function check() { var res = this.status(false); return res.currenthttpstatus === 200; }, function then() { var thisnow = hello[variable]; this.evaluate(function(valueoptionselect){ $('select#the_id').val(valueoptionselect); $('select#the_id').trigger('change'); },thisnow); }, function timeout() { // step execute if check has failed if(count < maxretry) { openit.call(this); } count++ }, 1000 //wait 1 sec ); } openit(); }
Comments
Post a Comment