为什么我的“超出限额"?我的某些使用基于时间的触发器的Google Apps脚本? [英] Why is my "limit exceeded" for some of my Google Apps scripts that are using time-based triggers?
问题描述
使用Google Apps脚本时,我的G Suite帐户似乎遇到某种未指定的限制,但是我不确定该限制是什么和/或应该如何调整工作流程.
I seem to be running up against some kind of unspecified limit with my G Suite account while using Google Apps scripts, but I'm not sure what the limit is and/or how I should adjust my workflow.
我有一个G Suite企业帐户.
I have a G Suite Business account.
我的"G Suite开发人员中心"中大约有45个相对简单的项目.
I have about 45 relatively simple projects in my "G Suite Developer Hub".
每个项目只有一个具有单个功能的小脚本,并设置了基于时间的触发器,每天在2:00 am至3:00 am之间运行.
Each project has just one little script with a single function, set with a time-based trigger to run daily between 2:00 am and 3:00 am.
每个项目的存在只是每天一次将文件从一个文件夹移动到另一个文件夹.每个项目都存在不同的文件夹对.
Each project exists just to move files from one folder to another, once a day. Each project exists for a different pair of folders.
这是每个项目中一个名为Code.gs
的小文件的模板.
Here's the template for the one little file in each project, named Code.gs
.
var source_folder = DriveApp.getFolderById("xxxxxxxxsourceFolderIDxxxxxxxx")
var dest_folder = DriveApp.getFolderById("xxxxxxxxdestinationFolderIDxxxxxxxx")
function moveFiles() {
var files = source_folder.getFiles();
while (files.hasNext()) {
var file = files.next();
dest_folder.addFile(file);
source_folder.removeFile(file);
}
}
大多数触发器似乎都可以正常工作,但是最近我收到了其中两个触发器失败的通知:
Most of the triggers seem to work just fine, but I was recently notified of trigger failures for two of them:
Start | Function | Error Message | Trigger | End
6/5/19 2:43 AM | moveFiles | Limit Exceeded: Drive. (line 13, file "Code") | time-based | 6/5/19 2:43 AM
第13行只是:source_folder.removeFile(file);
为什么会发生这种情况,如何确定自己没有受到这种限制?
Why is this happening, and how can I make sure that I don't suffer this limitation?
推荐答案
您的45个触发器在一段时间内很可能执行了太多操作.
It's very likely that your 45 triggers are doing too many operations for a time period. There are many alternatives,
- 与其将所有触发器设置为同时运行,不如以某种方式分配它们,例如,将9个触发器设置为在晚上11点运行,将9个触发器设置在上午12点,依此类推.
- 使用多个帐户而不是使用1个帐户来设置所有触发器.
- 创建45个脚本而不是创建一个主"脚本.也许您应该在每次文件夹/文件迭代时添加一个Utilities.sleep(毫秒).这是一种微调,具体取决于要移动的文件数和设计主脚本的方式.
这篇关于为什么我的“超出限额"?我的某些使用基于时间的触发器的Google Apps脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!