Suppose I have a function as given below. I am facing a problem of Exceeding maximum execution time. This is because function a,b & c are executing one after the other without giving google server a breathing space. I want to give that breathing space so that maximum execution error doesn't occur. To do that I would like to give it a 5 mins delay between execution of each function a,b and c in this case.
function main(){
a();
b();
c();
}
The above function should work like this:
function main(){
a();
rest for 5 mins before executing the next function
b();
rest for 5 mins before executing the next function
c();
}
I can't figure out how to achieve this?
CodePudding user response:
Your assumption is wrong. That error message is not related to how busy google app script is but to the total execution time being exceed by your main function.
In other words, your main function is taking more time than the allowed for a execution in app script, regardless of what you are doing in that function.
The solution then is not to add sleep or idle times since that will make the situation even worse.
The only solutions to expand the time limits are:
Create a trigger to run every N minutes and develop a system to track what to execute next (if something is not already running). It could be using the built-in cache or even a google sheet tab to maintain that internal system status.
Programmatically create and remove triggers, so that when function A starts, you can remove a trigger (code) to avoid future executions and when it ends you can create it (code) to run the next step. Once again, you need a way to maintain the internal system status.