【问题标题】:Google Sheet Add-on timeout ~ 45 seconds? [closed]Google Sheet 插件超时 ~ 45 秒? [关闭]
【发布时间】: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

点击我的功能时出现错误消息:

插件出错。 运行时错误。 超过最大执行时间

【问题讨论】:

标签: google-apps-script google-sheets add-on


【解决方案1】:

问题:

Card service 中,Action 调用的回调函数有 30 秒的执行时间限制:

警告:Apps 脚本Card service 将回调函数的执行时间限制为最长 30 秒。如果执行时间超过此时间,您的插件 UI 可能无法正确更新其卡片显示以响应 Action

参考:

【讨论】:

  • 谢谢!我猜这个 30 秒的执行时间限制现在已经被 Google 更改为 45 秒。
猜你喜欢
  • 2011-06-13
  • 2018-05-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-18
  • 2021-12-14
  • 1970-01-01
相关资源
最近更新 更多