내가 실행> 육분을 작업 수십 있습니다. 나는 수년에 걸쳐 조정 한 "outerloop"스크립트 (아래)를 사용합니다. 소요되는 시간과 상관없이 각 작업을 완료까지 실행합니다.
설정 (단지 가이드 - 당신이 당신의 자신의 특정 시나리오에 적용 할 필요) :
- 변경 처리하려는 어떤에 선
var thingies =
. 이상적으로는 배열이어야합니다.
//do our work here
줄 뒤에 코드 추가
outerLoop()
이라는 함수에 대한 트리거를 x 시간/일마다 실행하도록 설정하십시오. doProcessWidgets()
과 같은 의미있는 이름으로 바꿀 수 있습니다.
코드 : 내가 이해
G 스위트 조직의 경우
//automatically invoked from outerLoop()'s 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;
}
}
, 당신의 답변을 당신에게 제한을 늘릴 수있는 방법이 없다는 것을 특히 설명을 대단히 감사합니다. 장기 실행 스크립트를 다루는 정보에 감사드립니다. Google 문서에서 읽고 약 1500 행 50 열로 Google 스프레드 시트를 만드는 스크립트가 있습니다. PropertiesService에 저장할 수있는 것 이상이라고 가정합니다. 사용자가 시작점과 처리 할 수를 지정하는 스크립트 측면에서 생각한 다음 스크립트를 다시 실행합니다. 그래서 타이밍을 잡아서 트리거를 사용하여 다시 시작하는 것이 좋습니다. Peter와 Vytautas의 답변에 다시 한번 감사드립니다. –
이 의견은 질문이 아니라 대답에 게시해야합니다. 그런데 [어떻게 대답합니까 @reply work?] (https://meta.stackexchange.com/q/43019/289691) –