2
votes

I have a piece of code that is supposed to create a folder for each email message in a thread, and save the body (as a pdf) and all the attachments (as whatever they are) into that folder.

If I run it without the loop for saving the attachments, I have no problem. (Well, I have a different problem for a different thread). If I uncomment the attachments loop, I get

Service invoked too many times in a short time: driveWriteVolume rateMax. Try Utilities.sleep(1000) between calls. (line 156, file "Code")

All lines that create a folder or a file are followed by a Utilities.sleep(sleepTime); and sleeptime is currently set to 1000. Changing it doesn't seem to have any effect.

The offending piece of code is:

        // Save attachments
        for(var i = 0; i < messageAttachments.length; i++) {
          var attachmentBlob = messageAttachments[i].copyBlob();
          newFolder.createFile(attachmentBlob);
          Utilities.sleep(sleepTime);  // wait after creating something on the drive.
        } // each attachment

it is the newFolder.createFile(attachmentBlob); line that triggers the error.

I have looked at What is driveWriteVolume rateMax? and Intermittant DriveWriteVolume rateMax exception for help, and have found none.

Note that if I comment out the loop for attachments, and just save the messages bodies as PDF, I have no problem, regardless of the number of emails I'm saving. When I get the error, the script has died right where it should have saved the first attachment. So I'm thinking there is something else wrong than exceeding some sort of limit.

1

1 Answers

0
votes

Your hitting a rate limit. Google api probably has a limit of approx 20 writes / minute, so you'll need to slow your script down in order to avoid triggering the rate limit. In What is driveWriteVolume rateMax? the user in the similar thread used a time of 3000 ms to solve the problem rather than the suggested 1000 ms.