【问题标题】:script exceeding driveWriteVolume rateMax脚本超过 driveWriteVolume rateMax
【发布时间】:2013-05-24 23:30:49
【问题描述】:

我有一段代码应该为线程中的每封电子邮件创建一个文件夹,并将正文(作为 pdf 格式)和所有附件(无论它们是什么)保存到该文件夹​​中。

如果我在没有保存附件的循环的情况下运行它,我没有问题。 (好吧,我对不同的线程有不同的问题)。如果我取消注释附件循环,我会得到

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

所有创建文件夹或文件的行后跟一个Utilities.sleep(sleepTime);,并且 sleeptime 当前设置为 1000。更改它似乎没有任何效果。

有问题的代码是:

        // 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

触发错误的是newFolder.createFile(attachmentBlob); 行。

我查看了What is driveWriteVolume rateMax? 和Intermittant DriveWriteVolume rateMax exception 寻求帮助,但没有找到。

请注意,如果我注释掉附件循环,并将邮件正文保存为 PDF,无论我保存多少电子邮件,我都没有问题。当我收到错误时,脚本已经死在它应该保存第一个附件的地方。所以我认为除了超出某种限制之外还有其他问题。

【问题讨论】:

    标签: google-apps-script gmail google-sheets google-apps


    【解决方案1】:

    您达到了速率限制。 Google api 可能有大约 20 次写入 / 分钟的限制,因此您需要放慢脚本速度以避免触发速率限制。在What is driveWriteVolume rateMax? 中,类似线程中的用户使用了 3000 毫秒的时间来解决问题,而不是建议的 1000 毫秒。

    【讨论】:

    • 我尝试将其设置为高达 3000,但没有任何乐趣。为什么我在保存附件时会遇到限制 3 秒的暂停而在保存邮件时却没有?
    猜你喜欢
    • 2013-05-17
    • 2012-12-04
    • 2011-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-05
    • 2011-11-02
    相关资源
    最近更新 更多