GAS triggers randomly disabling after being created programmatically

被刻印的时光 ゝ 提交于 2021-02-11 14:00:39

问题


I have created a few trigger chains that fire at specific times over a weekend. I have chained them due to the limit of 20 timed triggers available to me.

Randomly a newly created trigger on the chain will become disabled and therefore not run. Obviously this ruins the entire chain and completely messes up what I'm trying to achieve.

I thought there may have been an issue in the ordering of exactly when I created the new trigger in the code, but this doesn't seem to be the case.

I'm wondering whether deleting a trigger within the script that it calls may be the cause of the issue - but I cannot think of an alternative way to code it.

Here's a portion of the chain code:

function mastersResultsAmericas1() {
  var region   = "Americas";
  var rSpot    = 1;
  var bgcolour = "#ffe1bc";

  mrAmericasTC2();
  mastersResults(region, rSpot, bgcolour);
  delTrigger("mastersResultsAmericas1");
}


function mrAmericasTC2() {
  ScriptApp.newTrigger("mastersResultsAmericas2")
    .timeBased()
    .atHour(9)
    .nearMinute(50)
    .onWeekDay(ScriptApp.WeekDay.SATURDAY)
    .inTimezone("PST8PDT")
    .create();
}

They chain all the way up to 5 and then that resets and creates the 1 trigger once again.

Here is the code I use to delete the triggers:

function delTrigger(trigger) {
  var triggers = ScriptApp.getProjectTriggers();
  for (var i = 0; i < triggers.length; i++){ 
    if (triggers[i].getHandlerFunction().indexOf(trigger) != -1) 
    {
      ScriptApp.deleteTrigger(triggers[i]);
      break;
    }
  }
}

I have found this link referring to disabled triggers - but the answer is not applicable to me. I am the only user and the only person who has access to the spreadsheet.


回答1:


My workaround was a result of the answer to this question.

Basically I just built code into an existing trigger that checked the day/time and ran the specific function if conditions were met. No longer need the trigger chain, nor to create any extra triggers programmatically (other than the initial setup).



来源:https://stackoverflow.com/questions/60789236/gas-triggers-randomly-disabling-after-being-created-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!