google-apps-scriptgoogle-sheetstriggersgoogle-workspace-add-ons

Google Sheet Add-on timeout ~ 45 seconds?


My google Sheet Add-on stops after 45 seconds after I trigger one function through the UI. I get the error "Exceeded maximum execution time"

I don't expect this. My understanding is that the max time should be 6 minutes for a google app script. Is it different in google sheet add-on?

To debug, I've reduced my script to the bare minimum and my function is just a plain sleep. This fails after 45 seconds still. PS: my function is not inside an onEdit. Thanks for your help

Code.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: Sidebar, with just one button

Sidebar with just one button

Error message when I click on my function:

Error with the add-on.
Run time error.
Exceeded maximum execution time


Solution

  • Issue:

    In Card service, callback functions invoked by an Action have a 30-second execution time limit:

    Warning: The Apps Script Card service limits callback functions to a maximum of 30 seconds of execution time. If the execution takes longer than that, your add-on UI may not update its card display properly in response to the Action.

    Reference: