如何将指数退避编程到 Google Sheets 脚本中?

问题描述

如何将指数退避编程到此脚本中,以便在我遇到错误时它会尝试再次运行?

遇到的错误

  • 为此 Google 用户帐户同时运行的脚本过多。
  • 同时调用过多:电子表格
  • 超过最大执行时间
  • 异常:同时调用过多:onEdit(Code:3:9) 中的电子表格
  • 访问 ID 为 __________ 的文档时,服务电子表格失败。

脚本:

function onEdit() {
  var s = SpreadsheetApp.getActiveSheet();
  if( s.getName() == "FORD" ) {
    var r = s.getActiveCell();
    if( r.getColumn() == 3) {
     
      var nextCell = r.offset(0,19);
      if( nextCell.getValue() === '' )
        nextCell.setValue(new Date()).setNumberFormat('MM/dd/yyyy HH:mm:ss');
    }
    
    if( r.getColumn() == 7) {
      var nextCell = r.offset(0,16);
      if( nextCell.getValue() === '' )
        nextCell.setValue(new Date()).setNumberFormat('MM/dd/yyyy HH:mm:ss');
    }
  }
}

任何其他改进我的脚本的建议总是受到赞赏! =)

解决方法

对于您提到的错误,指数退避没有用,因为它们是配额错误:

查看quota limitations

limitations