复制文件时超出脚本运行时配额 [英] Script runtime quota exceeded when copying files
问题描述
我试图制作模板文件的副本,并与所有员工分享。
我创建了一个Google表单,其中列出了名称雇员,他们的电子邮件地址,他们经理的电子邮件地址以及他/她正在工作的公司。
我已经写了下面的脚本: 函数CopyAndShare(模板,名称,电子邮件,ManagerEmail,公司){
var CompanyFolder = DriveApp.searchFolders(title ='+公司+').next();
Template.makeCopy(Vacationdays 2015+ Name,CompanyFolder)
// .addEditor(电子邮件)
// .addViewer(ManagerEmail);
Logger.log(Copy for:%s。,Name);
函数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跳过标题
CopyAndShare(BaseFile,Employees [i] [0],Employees [i] [1],员工[i] [2],员工[i] [3]);
$ b $ p
$ b 作为测试,我使用addEditor运行了此脚本, addViewer函数调用被禁用。在复制120份(并且运行6分钟)之后,脚本停止声称超出运行时配额。
我有点惊讶,创建120个副本需要6分钟。我想制作大约250份,所以我在那里一半。
我可以做些什么来加速我的脚本,所以我不会在6分钟内运行。 p>
我在Google Apps for Work网域中执行此操作。
> Bruce Mcpherson在Google Apps脚本中编写了一个并行处理工具。它的目的是让你在6分钟的时间内完成任务。
http://ramblings.mcpher.com/Home/excelquirks/htmlservice/parallel
http://ramblings.mcpher.com/Home/excelquirks/htmlservice/parallel/implement
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.
解决方案 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
这篇关于复制文件时超出脚本运行时配额的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!