【问题标题】:Intermittant DriveWriteVolume rateMax exception间歇性 DriveWriteVolume rateMax 异常
【发布时间】:2013-05-17 16:17:34
【问题描述】:

在 DriveApp 发布前大约一周,我一直在努力解决这个错误。我有一段代码因错误而间歇性失败:

服务在短时间内调用太多次:driveWriteVolume rateMax。在两次通话之间尝试 Utilities.sleep(1000)。

这里是有问题的代码:

for(var a = 0; a<attachments.length; a++){

   if(a > 0){
     child = "." + (a + 1) + " ";
   }
   else{
     child = ".1 ";
   }

   var parent = (m + 1);
   Utilities.sleep(5000);
   var file = attachmentFolder.createFile(attachments[a]);//This is the line that causes the error.
   Utilities.sleep(1000);
   file.rename(parent + child + attachments[a].getName());

}

我从 1000 毫秒开始,然后逐渐增加到 5000 毫秒,但它仍然每 200 次迭代就会抛出错误。这是使用 DocsList。

【问题讨论】:

    标签: google-apps-script


    【解决方案1】:

    我正在处理的脚本中遇到了类似的问题。

    当我遍历邮件的附件并尝试保存它们时,问题就出现了。如果我跳过附件,我没有问题,即使文件创建总数相同且它们之间的睡眠时间相同。这是我正在使用的代码。 newFolder.createFile(pdfBlob) 不会引起问题。 newFolder.createFile(attachmentBlob) 会。

            // Create the message PDF inside the new folder
            var htmlBodyFile = newFolder.createFile('body.html', messageBody, "text/html");
            var pdfBlob = htmlBodyFile.getAs('application/pdf');
            pdfBlob.setName(newFolderName + ".pdf");
            newFolder.createFile(pdfBlob);
            Utilities.sleep(sleepTime);  // wait after creating something on the drive.
            htmlBodyFile.setTrashed(true);
    
    
            // Save attachments
            Logger.log("Saving Attachments");
            for(var i = 0; i < messageAttachments.length; i++) {
              Logger.log("Saving Attachment " + i);
              var attachmentBlob = messageAttachments[i].copyBlob();
              newFolder.createFile(attachmentBlob);
              Utilities.sleep(sleepTime);  // wait after creating something on the drive.
            } // each attachment
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-01
      相关资源
      最近更新 更多