问题
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.
I have a G Suite Business account.
I have about 45 relatively simple projects in my "G Suite Developer Hub".
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.
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
Line 13 is just: source_folder.removeFile(file);
Why is this happening, and how can I make sure that I don't suffer this limitation?
回答1:
It's very likely that your 45 triggers are doing too many operations for a time period. There are many alternatives,
- Rather than setting all the triggers to run at the same time, distribute them some way, let say set 9 triggers to run at 11 pm, 9 triggers at 12 am, etc.
- Rather than using 1 account to set all the triggers, use several accounts.
- Rather than having 45 scripts create one "master" script. Maybe you should add a Utilities.sleep(milliseconds) at each folder/file iteration. This is some sort of fine tuning that will depend on how many files are being moved and how you design your master script.
来源:https://stackoverflow.com/questions/56465113/why-is-my-limit-exceeded-for-some-of-my-google-apps-scripts-that-are-using-tim