Skip to content

Instantly share code, notes, and snippets.

@bassmanitram
Last active April 6, 2023 16:19
Show Gist options
  • Save bassmanitram/20daa3627d78d5d0b3eb91572efdccd9 to your computer and use it in GitHub Desktop.
Save bassmanitram/20daa3627d78d5d0b3eb91572efdccd9 to your computer and use it in GitHub Desktop.
function doGet() {
try {
const savedConfig = PropertiesService.getUserProperties();
const triggerId = savedConfig.getProperty('TriggerId');
if (triggerId) {
Logger.log("Looking for triger", triggerId)
let t = ScriptApp.getProjectTriggers();
for (let trigger of t) {
if (trigger.getUniqueId() == triggerId) {
Logger.log("Removing trigger", triggerId, trigger);
ScriptApp.deleteTrigger(trigger)
break
}
}
savedConfig.deleteProperty('TriggerId')
}
Logger.log("Creating new trigger")
const newTriggerId = ScriptApp.newTrigger('triggerFunction')
.timeBased().everyMinutes(15)
.create().getUniqueId();
Logger.log("New trigger", triggerId)
savedConfig.setProperty('TriggerId', newTriggerId);
return HtmlService.createHtmlOutput(`Trigger ${triggerId} created`)
} catch (e) {
Logger.log("Trigger stuff failed", e)
return HtmlService.createHtmlOutput(`Trigger stuff failed ${e}`)
}
}
function triggerFunction(event) {
try{
Logger.log(event);
} catch(e) {
Logger.log(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment