【发布时间】:2019-10-15 12:33:39
【问题描述】:
我试图在 1 秒后触发函数的执行,但谷歌在 40 秒或 2 分钟后执行该函数。
这是我的代码
function testFunc () {
Logger.log("test called");
}
function myFunction() {
const now = Date.now();
const dateNow = new Date(Date.now());
const dateLater = new Date(now + 1000);
const trigg = ScriptApp.newTrigger('testFunc')
.timeBased()
.inTimezone("Europe/Paris")
// .at(dateLater) // 1sec
.after(1000) // 1sec
.create();
}
我尝试使用 after 和 at 函数,但两者都不起作用。
当我查看执行页面时,我有这段历史记录显示执行myFunction 和testFunc 之间的时间。
Head testFunc Time-Driven Oct 15, 2019, 2:06:35 PM 0.009 s
Completed
Head myFunction Editor Oct 15, 2019, 2:05:33 PM 0.589 s
Completed
Head testFunc Time-Driven Oct 15, 2019, 2:04:15 PM 0.202 s
Completed
Head myFunction Editor Oct 15, 2019, 2:02:57 PM 0.46 s
Completed
documentation on time driven triggers 这么说
时间可能会稍微随机化 - 例如,如果您创建一个重复的上午 9 点触发器,Apps 脚本会选择上午 9 点到 10 点之间的时间。
我正试图让我的触发器在几秒钟后(5 到 10 秒之间)执行,有什么办法吗?
【问题讨论】:
标签: google-apps-script google-sheets triggers google-apps