Too many simultaneous invocations: Spreadsheets

1,851 views
Skip to first unread message

Juan David Paladines

unread,
May 24, 2021, 11:40:21 AM5/24/21
to Google Apps Script Community
I'm using this code to access to the information of a Spreadsheet with too much data. The error is shown in the "valores" variable, in getDataRange().
Captura de pantalla 2021-05-24 103423.png
How can I optimize that function or which other function can I use to make the trigger work properly?

Alan Wells

unread,
May 24, 2021, 12:12:02 PM5/24/21
to Google Apps Script Community
There are a couple of things that you can try.
If your code is getting triggered often, and multiple times in rapid succession, then you should implement LockService.

Then there is the issue of services being used too often in a short period of time, and hitting the quota limit.
For that situation, you need to use a "backoff" technique in your code, where you try and then catch an error, wait and try again.
  var L = 4;//Try up to 3 times
  
  for (var i=1;i<L;i++) {
    try{
      //Your code here
      break;//If successful then the loop will break
    }catch(e){
      if (i!==L-1){Utilities.sleep(i*1500);}
      if (i>=L-1) {
        Logger.log('error: '  + e.error)
        //console.error('ERROR - : ' + e + ' Stack: ' + e.stack + "\n\n" + r);
      }
    };
  }

Juan David Paladines

unread,
May 24, 2021, 12:35:22 PM5/24/21
to Google Apps Script Community
Okay, in this case the code is running too often with an approximate of 10 excecutions... Would this code, the one you posted, still working?

Juan David Paladines

unread,
May 24, 2021, 12:55:51 PM5/24/21
to Google Apps Script Community
Captura de pantalla 2021-05-24 114151.png
This is the actual amount of executions that the script has...
On Monday, May 24, 2021 at 11:12:02 AM UTC-5 aj.a...@gmail.com wrote:

Alan Wells

unread,
May 24, 2021, 1:53:03 PM5/24/21
to Google Apps Script Community
You should add the code that I gave you for the line those 3 lines of code that you posted.
Plus you should also add the LockService to your code.
You should do both.
If you want to try just the code that I posted, and see if that fixes the issue, you could do that.



Reply all
Reply to author
Forward
0 new messages