Script runtime quota exceeded when copying files [

2019-08-31 23:13发布

This question already has an answer here:

I'm trying to make copies of a template file and share them with all our employees.

I've created a Google Sheet which lists the names off the employees, their email address, the email address of their manager and the company he/she is working for.

I've written the following script:

function CopyAndShare (Template, Name, Email, ManagerEmail, Company) {
  var CompanyFolder = DriveApp.searchFolders("title = '" + Company + "'").next();
  Template.makeCopy("Vacationdays 2015 " + Name, CompanyFolder)
         // .addEditor(Email)
         // .addViewer(ManagerEmail);
  Logger.log("Copy created for: %s.", Name);
}

function DistributeFiles() {
  var BaseFile = DriveApp.getFileById("1KBCFA21HbGZRCQXAtghatd8BfpR1PN2N_3L7rYxj1PU"); 
  var Employees = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getDataRange().getValues();
  for (var i = 1, l = Employees.length; i < l; i++) { // i = 1 to skip header
    CopyAndShare(BaseFile, Employees[i][0], Employees[i][1], Employees[i][2], Employees[i][3]);
  }
}

As a test I ran this script with the addEditor and addViewer functioncalls disabled. After 120 or so copies (and 6 minutes running) the script halted saying the Runtime quota exceeded.

I am a bit surprised creating 120 copies took 6 minutes. I want to make about 250 copies so I was halfway there.

What can I do to speedup my script so I won't run in the 6 minute limit.

I'm doing this on a Google Apps for Work domain.

1条回答
\"骚年 ilove
2楼-- · 2019-08-31 23:28

Bruce Mcpherson has written a tool for parallel processing in Google Apps Script. It was designed to get you around the 6 minute limitation.

http://ramblings.mcpher.com/Home/excelquirks/htmlservice/parallel http://ramblings.mcpher.com/Home/excelquirks/htmlservice/parallel/implement

查看更多
登录 后发表回答