gpt4 book ai didi

google-apps-script - 无法以编程方式删除定时触发器

转载 作者:行者123 更新时间:2023-12-05 01:09:47 25 4
gpt4 key购买 nike

我有一个测试脚本,我试图在其中测试定时触发器。我需要能够以编程方式创建和删除触发器 - 根据文档,这是可能的。但是,我的触发器在需要时不会删除:

function myFunction() {
var db = ScriptDb.getMyDb();
var user = Session.getActiveUser().getEmail();
var triggerID = ScriptApp.newTrigger("timed").timeBased().everyMinutes(1).create().getUniqueId();

var ob = {
id: user,
count: 1,
trigger: triggerID
}

db.save(ob);
}

function timed(){
var db = ScriptDb.getMyDb();
var user = Session.getActiveUser().getEmail();
var ob = db.query({id: user}).next();
var count = ob.count;
var triggerID = ob.trigger;

if (count > 4){
deleteTrigger(triggerID);
db.remove(ob);

} else {
Logger.log(count + " " + Utilities.formatDate(new Date(), "GMT", "HH:mm:ss") + " TriggerID=" + triggerID);
ob.count = count+1;
db.save(ob);
}
}

function deleteTrigger(triggerID){
var allTriggers = ScriptApp.getProjectTriggers();

for(var i=0; i < allTriggers.length; i++){
if(allTriggers[i].getUniqueId() = triggerID){
ScriptApp.deleteTrigger(allTriggers[i]);
break;
}
}
}

最佳答案

要测试相等性,您只需要 ==而不是 =在以下行中:

if (allTriggers[i].getUniqueId() = triggerID) {

关于google-apps-script - 无法以编程方式删除定时触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15368152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com