How to increase the 6 minute execution limit in Google Apps script?

Is there a way to increase the 6-minute runtime for Google Apps scripts? I thought the answer might be an early access program for the G Business Suite. I could pay $ 10 a month for the G Business Suite if I could get into the early access program to increase the execution limit from 6 minutes to 30 minutes. But an adviser from the G Suite help forum said that Early Access is a limited program, which means that I cannot guarantee that I can get it.

Is there any other way to increase the 6 minute execution limit?

Please note that in this question I am not asking for ideas on how to optimize my scripts to fit the 6 minute limit. (I may ask that in the future, if the answer to this current question is "No, there is no other way.")

Therefore, the corresponding answers to this current question are:

  • "No, there are no other ways to increase the 6-minute execution limit for Google application scripts."
  • "Yes, there are other ways to increase the 6-minute execution limit, and these are the ways ..."
+4
source share
2 answers

, > 6 . "outerloop" script (), . , .

( - ):

  • var thingies = , . .
  • //do our work here
  • outerLoop() x /. , , doProcessWidgets().

:

//automatically invoked from outerLoop() creation of a new trigger if required to get work done
function outerLoopRepeating() {
  outerLoop();
}
// trigger this function
function outerLoop() {
  try {
    var processingMessage = 'Initialising', isOverMaxRuntime = false, startTime = new Date(), // calc elapsed time
        functionName = arguments.callee.name, repeatingFunctionName = functionName + 'Repeating'; //for logging, triggering

    // Deletes all occurrences of the Repeating trigger we don't end up with undeleted time based triggers all over the place
    //add library GASRetry MGJu3PS2ZYnANtJ9kyn2vnlLDhaBgl_dE
    GASRetry.call(function(){ScriptApp.getProjectTriggers().forEach(function(i) {
      if (i.getHandlerFunction() === repeatingFunctionName) {ScriptApp.deleteTrigger(i);}
    });});

    Logger.log('========== Starting the "%s" function ==========', functionName);

    // Handle max execution times in our outer loop
    // Get start index if we hit max execution time last run
    var start = parseInt(PropertiesService.getScriptProperties().getProperty(functionName + "-start")) || 0;

    var thingies = ['stuff to process', 'in an Array',,,,]; //
    for (var i = start ; i < thingies.length; i++) {
      if (Math.round((new Date() - startTime)/1000) > 300) { //360 seconds is Google Apps Script max run time
        //We've hit max runtime. 
        isOverMaxRuntime = true;
        break;
      }
      //do our work here
      Logger.log('Inside the for loop that does the xyz work. i is currently: %d', i);
      var processingMessage = Utilities.formatString('%d of %d thingies: %s <%s>',  i+1, thingies.length, thingyName, thingyId);

      //do our work above here
    }
    if (isOverMaxRuntime) {
      //save state in user/project prop if required
      PropertiesService.getScriptProperties().setProperty(functionName + '-start', i);
      //create another trigger
      GASRetry.call(function(){ScriptApp.newTrigger(repeatingFunctionName).timeBased().everyMinutes(10).create();});
      Logger.log('Hit max run time - last iteration completed was i=%s', i-1);
    } else {
      Logger.log('Done all the work and all iterations');
      PropertiesService.getScriptProperties().deleteProperty(functionName + '-start');
      Logger.log('Completed processing all %s things with the "%s" function', thingies.length, functionName);
    }
  } catch (e) {
    Logger.log('%s. While processing %s', JSON.stringify(e, null, 2), processingMessage);
    throw e;
  }
}
+3

G Suite, , , Early Access Program. Google

. , .

, script , script . script .

. , . , , , script . , , . script .

EAP, . script , , , , .

Q & A

+1

Source: https://habr.com/ru/post/1668478/


All Articles