Why is my “limit exceeded” for some of my Google Apps scripts that are using time-based triggers?

自闭症网瘾萝莉.ら 提交于 2019-12-11 06:37:23

问题


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,

  1. 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.
  2. Rather than using 1 account to set all the triggers, use several accounts.
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!