问题
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