1
votes

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
I guess, each file-operation is a http-request against the drive-api. Then you should look at the drive-api.Nikolaus
@Rubén Yes, but I don't understand what limit I might be up against. I'd just be shooting in the dark.user260467

1 Answers

3
votes

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.