I have a script that pulls data from an api every three hours after the initial pull has been made. I noticed that within my execution log there are more runs than I am accounting for. It looks like there are ‘clumps’ of runs every three hours instead of one run every three hours.
I call the delete trigger function at the beginning of my main script to ensure all triggers are deleted, and then call the create trigger function at the end so a trigger is created only if the entire main function was successful.
Any idea why there are multiple executions for one time based trigger?
/** Creates a trigger to run the main function */
function createPullTrigger(){
//creates a new trigger
ScriptApp.newTrigger('getData')
.timeBased()
.everyHours(3)
.create();
return;
}
/** Deletes all existing triggers. Apps scripts allows 20 triggers per user,
* so we don't want to create an overload of triggers.
*/
function deleteAllTriggers(){
//deletes all triggers that currently exist (if any)
var triggers = ScriptApp.getProjectTriggers();
console.log("Existing Triggers: "+triggers.length);
for (var i = 0; i < triggers.length; i++) {
console.log('triggers');
try{
ScriptApp.deleteTrigger(triggers[i]);
}
catch(e){
console.log('no triggers currently exist');
}
}
return ;
}
Chris Hernandez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.