通过程序创建后,GAS会随机禁用 [英] GAS triggers randomly disabling after being created programmatically

查看:33
本文介绍了通过程序创建后,GAS会随机禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一些触发链,这些触发链在一个周末的特定时间触发.由于我只能使用20个定时触发器,因此我已将它们链接起来.

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();
}

它们一直链接到 5 ,然后重置并再次创建 1 触发器.

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;
    }
  }
}

我发现链接是指禁用的触发器-但答案是不适用于我.我是有权访问电子表格的 only 用户和 only 用户.

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.

推荐答案

我的解决方法是对

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).

这篇关于通过程序创建后,GAS会随机禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆