Google Apps脚本递归计划触发器 [英] Google Apps Script recursive schedule trigger
问题描述
我正在尝试以编程方式将触发器添加到Google Apps脚本中-我想调度一个函数main()
,该函数使用这样的ScriptApp.newTrigger().create()
调用包装了另一个基于时间的触发器调用
I am trying to programmatically add a trigger to a Google Apps Script - I have a function main()
I want to schedule, which wraps another timebased trigger call using the ScriptApp.newTrigger().create()
call like this
function main(){
/*
* do stuff
*/
doScriptCallback();
}
function doScriptCallback(){
if(CONFIG.CALLBACK_SCRIPT_NAME != ''){
try {
ScriptApp.newTrigger(CONFIG.CALLBACK_SCRIPT_NAME)
.timeBased()
.after(5000)
.create()
Logger.log('Scheduled ' + CONFIG.CALLBACK_SCRIPT_NAME);
} catch(e) {
Logger.log(e);
}
}
}
在编辑器中运行
main()
正确运行doScriptCallback()
并安排CONFIG.CALLBACK_SCRIPT_NAME
running main()
from the editor correctly runs doScriptCallback()
and schedules the function in CONFIG.CALLBACK_SCRIPT_NAME
但是如果我安排main()
,则doScriptCallback
仅记录该消息,但该功能无法运行.
But if I schedule main()
then the doScriptCallback
only logs the message, but the function does not run.
这是Google Apps脚本中的限制吗?
Is this a restriction in Google Apps script?
推荐答案
这似乎是一个错误!
关于Google的问题跟踪器,已经有一份报告详细介绍了相同的行为:
This appears to be a bug!
There is already a report on Google's Issue Tracker which detail the same kind of behaviour:
Google似乎确实了解此问题,但是如果引起问题,您可以提交有关此问题的错误此处.
Google does seem to know about this issue but if it's causing problems you can file your own bug about it here.
您也可以在上述页面的左上方点击问题编号旁边的☆,让Google知道更多人正在遇到此问题,因此更有可能更快地看到它-看来这是一个常见问题.
You can also hit the ☆ next to the issue number in the top left on the aforementioned pages which lets Google know more people are encountering this and so it is more likely to be seen to faster - it already appears that this is a commonly encountered issue.
同时,您可以在Apps脚本中禁用V8运行时,这将在Rhino运行时中运行触发器.这些报告仅影响V8,我可以确认我能够运行Rhino中嵌套触发器创建的功能.
In the mean time it appears you can disable V8 runtime in Apps Script, and this will run your triggers in the Rhino run time. The reports only affect V8, and I can confirm I was able to run the function created by the nested trigger in Rhino.
您可以按照Run > Disable new Apps Script runtime powered by Chrome V8
禁用V8.
希望对您有帮助!
这篇关于Google Apps脚本递归计划触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!