【发布时间】:2021-09-04 15:08:58
【问题描述】:
在我通过 UI 触发一项功能后 45 秒后,我的 google Sheet Add-on 停止。我收到错误“超过最大执行时间”
我没想到会这样。我的理解是,谷歌应用脚本的最长时间应该是 6 分钟。谷歌表格插件有什么不同吗?
为了调试,我已将我的脚本减少到最低限度,我的功能只是简单的睡眠。这仍然在 45 秒后失败。 PS:我的函数不在 onEdit 中。 感谢您的帮助
代码.gs
function onHomepage(e) {
return createSelectionCard(e);
}
function createSelectionCard(e)
{
var builder = CardService.newCardBuilder();
builder.addSection(CardService.newCardSection()
.addWidget(CardService.newButtonSet()
.addButton(CardService.newTextButton()
.setText('myfunction')
.setTextButtonStyle(CardService.TextButtonStyle.FILLED)
.setOnClickAction(CardService.newAction().setFunctionName('myfunction'))
.setDisabled(false))));
return builder.build();
}
function myfunction(e) {
// this should pause for 1 minute, but breaks after 45 seconds
Utilities.sleep(300000/5);
return createSelectionCard(e)
}
appsscript.json
{
"timeZone": "America/New_York",
"dependencies": {},
"exceptionLogging": "STACKDRIVER",
"oauthScopes": [
"https://www.googleapis.com/auth/spreadsheets.currentonly"
],
"runtimeVersion": "V8",
"addOns": {
"common": {
"name": "test",
"logoUrl": "https://www.gstatic.com/images/branding/product/1x/translate_24dp.png",
"layoutProperties": {
"primaryColor": "#2772ed"
},
"homepageTrigger": {
"runFunction": "onHomepage"
}
},
"sheets" : {}
}
}
用户界面: UI with just one button
点击我的功能时出现错误消息:
插件出错。 运行时错误。 超过最大执行时间
【问题讨论】:
-
欢迎来到Stack Overflow。 “在我通过 UI 触发一个功能之后”是什么意思?您在使用自定义菜单吗?请记住,寻求调试帮助的问题应包括minimal reproducible example。
-
没有例子?没有帮助:帮助;
-
嗨,this answer 对您有用吗?如果是这种情况,请考虑接受这个stackoverflow.com/help/someone-answers。
标签: google-apps-script google-sheets add-on