Home > Software engineering >  Google app script exceeded maximum execution time
Google app script exceeded maximum execution time

Time:02-17

I am getting the error "exceeded maximum execution time" on running the below script. trying to run a cron on my website and each url takes time to process in my website which leads to exceeding the time limit. Once url processed in the website it shows the message from the link in the execution log. How can i make the script run again from start or from url it stopped.

function getUrls() {
try {
var urls = [ 'https://www.testurl.com/link1=processing',
             'https://www.testurl.com/link2=processing',
             'https://www.testurl.com/link3=processing',];

function getUrl(url) {
  var response = UrlFetchApp.fetch(url).getContentText();
  if ( response.indexOf("triggered") >-1 ) {
      Logger.log(response);
    }
  while ( response.indexOf("complete") >-1 ) {
      Logger.log(response);
      return 0;
    }
  }

urls.forEach( getUrl );
}
catch(err) {
Logger.log(err);
}
}

CodePudding user response:

Your while condition lasts forever. The result of the condition never changes therefore if it is true once, it will run forever.

Or, you are calling getUrl in your forEach and that also leads to it calling itself over and over again. I think that is the real issue.

CodePudding user response:

Try this:

function getUrls() {
  const urls = ['https://www.testurl.com/link1=processing', 'https://www.testurl.com/link2=processing', 'https://www.testurl.com/link3=processing'];

  urls.forEach(u => {
    let response = UrlFetchApp.fetch(u).getContentText();
    if (~response.indexOf("triggered")) {
      Logger.log(response);
    }
  });
}

BitWise not

  • Related