, > 6 . "outerloop" script (), . , .
( - ):
var thingies = , . .//do our work hereouterLoop() x /. , , doProcessWidgets().
:
function outerLoopRepeating() {
outerLoop();
}
function outerLoop() {
try {
var processingMessage = 'Initialising', isOverMaxRuntime = false, startTime = new Date(),
functionName = arguments.callee.name, repeatingFunctionName = functionName + 'Repeating';
GASRetry.call(function(){ScriptApp.getProjectTriggers().forEach(function(i) {
if (i.getHandlerFunction() === repeatingFunctionName) {ScriptApp.deleteTrigger(i);}
});});
Logger.log('========== Starting the "%s" function ==========', functionName);
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) {
isOverMaxRuntime = true;
break;
}
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);
}
if (isOverMaxRuntime) {
PropertiesService.getScriptProperties().setProperty(functionName + '-start', i);
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;
}
}