Last active
April 6, 2023 16:19
-
-
Save bassmanitram/20daa3627d78d5d0b3eb91572efdccd9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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