Workspace Add-on Card Execution Time

60 views
Skip to first unread message

Phillip Bainbridge

unread,
Nov 13, 2021, 5:39:35 AM11/13/21
to Google Apps Script Community
Hi all

I'm looking for some advice please on any suggestions to overcome creating a Google Workspace Add-on that needs to execute code that takes longer than the 30 second limit allowed for the Card Service?

Basically I have a previous tool (a Google Sheet with a bound Apps Script file) that is designed to scan a users Drive for all of the files they own. Currently everybody makes a copy of the Google Sheet so they can use the tool themselves (which introduces version control issues). So I wanted to turn it into a Google Workspace Add-on and use the Card Service in the Sidebar to perform this task (hence I could provide future updates seamlessly without multiple copies of the Google Sheet out there).

Understandably the tool may end up running for several minutes however and currently with the Card Service it requires an execution time of less than 30 seconds so the Card UI can update! This means I've hit a brick wall in figuring out how I could roll this out as a simple Add-on for everybody.

Thank you in advance.
Phil

Martin Hawksey

unread,
Nov 16, 2021, 5:21:37 PM11/16/21
to Google Apps Script Community
Hi Phil,

There are some big add-ons that still use HTMLService and I would imagine execute limits would be one reason for doing this.

The common model, even used by Google as part of take out, is to start the process letting the user know that they will receive an email when finished. As your add-on has a limited execution you'll have to probably use it to orchestrate a separate runtime script, calling a published web app which creates a script trigger could be one way of doing it.  


Changes
- Common.gs lines 112-120 // (see executing web apps client side situation 5 (user would need to open the web app url once in browser to authorise https://github.com/tanaikech/taking-advantage-of-Web-Apps-with-google-apps-script/blob/master/README.md#google-apps-script )
- Added WebApp.gs to create a trigger for the sendEmail (using a trigger so that the web app execution doesn't block the changeCat function)  

Leandro Zubrezki

unread,
Nov 19, 2021, 9:41:56 AM11/19/21
to Google Apps Script Community
I would advise to avoid using HTMLService, it has a lot of issues with multiple user accounts and if you are planning to release it to the Marketplace you will start to see problems pretty soon.

As Martin mentions, the best way is to do the processing server side and let the user know by email once it's done. In my add-on I show a GIF as spinner plus change the color of the sheet tab to let them know that something is running and provide a REFRESH button to rebuild the UI getting the latest information.

Additionality you can use a spreadsheet to give immediate feedback, adding an image, change the value of a cell, etc.

Phillip Bainbridge

unread,
Nov 21, 2021, 1:19:38 PM11/21/21
to Google Apps Script Community
Hello

Very sorry for the delay in responding - I've been consumed by the world of Add-ons, HTMLService & Apps Script recently!!! As I saw your messages and went off exploring.

Thank you Martin & Leandro for taking the time to get back to me here. I have started exploring Web Apps a little bit more recently as well as the HTMService for dialogue boxes when using a Google Sheet. At the moment I have gone down the route of an Editor Add-on for now. I have my HTMLService dialogue boxes terminating before triggering Apps Script code to run. I also have a way of triggering a final dialogue box after 5.5 minutes that allows the user to 'Resume' scanning for files (which restarts the Execution Time).

I've no way to test this at scale - other than 3 or 4 accounts I have created. I'd like to get this version completed (rather than abandon it at this stage) and then explore your suggestions with offloading to a Web App in some way.

Kind regards
Phil


Reply all
Reply to author
Forward
0 new messages