Working with multiple function calls in sheets
carlos-ferrer opened this issue · comments
I have a worksheet with 100+ requests to an API; it works ok the first time I set it up, but returns a 429 error as soon as it auto-refreshes. since it tries refreshing every occurance of the function at the same time. I can't do just one request because the way the api organizes the data.
Is it possible to set up a delay so that Sheets doesn't try refreshing multiple instances of this function at the same time?
yes i have this issue too on occasion, along with "urlfetch exceeding" problems . i just cannot get over it seems :(
Ok, I think I found a workaround using Lock.
Write this Inside do_import_ function (else at line 70):
else {
let lock = LockService.getScriptLock();
lock.waitLock(15000);
json = do_fetch_(url, params);
lock.releaseLock();
}
This prevents multiple functions from trying to fetch data at the same time - it locks the formulae for a maximum time of 15 seconds (can lower or increase depending on amount of data, too little time and it returns a lock timeout error).
Before doing this most of the data would return a 429; hasn't happened once after I added the lines above.