什么是driveWriteVolume rateMax?

时间:2013-05-09 19:23:25

标签: google-apps-script

我最近开始得到这个例外:

driveWriteVolume rateMax. Try Utilities.sleep(1000) between calls

通常这意味着我正在尝试快速重复访问服务。但是,我之前从未见过这条消息,而且我所做的任何搜索都没有返回任何有用的信息。

这是我可以做的最好的模型,没有粘贴100行代码:

function compileLabel(){
   var doc = DocsList.createFile('My Label', '', 'text/html');
   var threads = GmailApp.getUserLabelByName('My Label');

   var startTime = Date.now();
   while((Date.now() - startTime) < 240000){

     for(t in threads){
        var messages = threads[t].getMessages();
        var threadHeader = createThreadHeader(); //Builds HTML representation of thread info as string
        doc.append(threadHeader);

        for(m in messages){
           var msgHeader = createMessageHeader(); //Builds HTML representation from header info as string
           doc.append(msgHeader);
           doc.append(messages[i].getBody());

           var attachments = messages[m].getAttachments();
           if(attachments.length > 0){
              var attachmentFolder = parentFolder.createFolder(messages[m].getSubject());
           }
           for(a in attachments){
             attachmentFolder.createFile(attachments[a]);
           }
        }
     }
   }

   parentFolder.createFile(doc.getAs('application/pdf')); //this is intermittantly throwing an exception about serialization now, but that's probably a different issue.
   //After time based loop, do more things that don't have any DocsList based functions
}

截至2天前,这项工作非常顺利。现在,除非我sleep(1000)doc.append()createFile()之前的createFolder(),否则会产生此错误。如有必要,我可以提供项目密钥。

1 个答案:

答案 0 :(得分:0)

我今天发现了同样的错误邮件,显然我超过了允许上传到Google云端硬盘的费率。为了解决这个问题,我必须将睡眠时间增加到3000(我已经使用了1000)。这是导致错误的代码段:

  var att = messages[y].getAttachments(); 
  var attlinks = [];  
  for (var z=0; z<att.length; z++) {
    try {
      var file = folder.createFile(att[z]); //create file in gdrive
      attlinks.push('<a href="'+file.getUrl()+'" target="_blank" alt="'+file.getName()+'">'+file.getName()+'</a>'); //push link to array
      Utilities.sleep(3000); //increased from 1000 to 3000
    }

<强>更新

我不得不再次增加睡眠时间(至10秒),因为当附件数超过5时问题仍然存在。