3

我必须在我的谷歌电子表格中设置很多触发器来更新一些工作表。

为了避免一项痛苦的任务,我手动设置了一个触发器,该触发器以编程方式设置所需的其他触发器,根据任务(批处理等......)

好吧,这是我调用来创建这些触发器的函数

function createTriggers(sheet, hour){
  var nbTrigger = sheet.getLastColumn() * sheet.getLastRow() / 1100 + 1 ;
  var buffHour = new Date().getHours();
  var min = new Date().getMinutes()+10;
  if(min >=60){
    min = min % 60;
    buffHour++;
    if(buffHour>=24){
      buffHour = buffHour % 24;
    }
  }
  //Browser.msgBox(buffHour+"h"+min);
  var ok = false;
  var cpt = 0;
  do {
    try {
     ScriptApp.newTrigger("triggered").timeBased().atHour(new Date().getHours()).nearMinute(Math.abs(1)).everyDays(1).create();
      ok = true;
    } catch(e) {
      Logger.log(e);
      Utilities.sleep(1000);
      cpt++;
    } 
  }while(!ok && cpt<10);

  if(cpt>10){
    throw "Was unable to create a trigger...";
  }

  for(var i = 0; i<nbTrigger; i++){
    ok = false;
    cpt = 0;
    do {
      try {
        var trigger = ScriptApp.newTrigger("update").timeBased().atHour(buffHour).nearMinute(Math.abs(min)).everyDays(1).create();
        ok = true;
      } catch(e) {
        Logger.log(e);
        Utilities.sleep(1000);
        cpt++;
      }
    } while(!ok && cpt<10);

    if(cpt>10){
      throw "Was unable to create a trigger...";
    }

    Utilities.sleep(10000);
    min +=7;
    if(min >= 60){
      buffHour++;
      min = 0;
      if(buffHour == 24){
        buffHour = 0;
      }
    }
  }
}

因此,我必须将触发器的创建放入 try catch 块中:

Wed May 09 13:36:41 PDT 2012 INFO: Exception: Invalid value -2 for field MINUTE, should be between [Range:0, 59]
Wed May 09 13:36:42 PDT 2012 INFO: Exception: Invalid value -8 for field MINUTE, should be between [Range:0, 59]
Wed May 09 13:36:43 PDT 2012 INFO: Exception: Invalid value -7 for field MINUTE, should be between [Range:0, 59]
Wed May 09 13:36:44 PDT 2012 INFO: Exception: Invalid value -7 for field MINUTE, should be between [Range:0, 59]

它从何而来 ??为什么不是每次都发生??我能做些什么来避免这种情况?

谢谢 !

4

1 回答 1

0

感谢您提出这个问题 - 这是 ClockTriggerBuilder.nearMinute() 方法中的一个错误。我已经在问题跟踪器中为您提出了它:http ://code.google.com/p/google-apps-script-issues/issues/detail?id=1320 。如果您为它加注星标,您将了解它的进度。

As a workaround in the meantime, pass minute values to the nearMinute() method that are between 8 and 52, inclusive.

于 2012-05-10T14:05:13.617 回答