I have a google script with 4 different functions that need to run one after another, but a function can run just after the previous one has finished/completed.
The time that takes each function depends, but on average each function takes about 15-20 minutes.
Each function completes an spreadsheet with a lot of data, so I want to run the first function, wait until the first one ends, run the second one, etc. inside a trigger to load the information every (for example) 4 hours.
Thanks!
In the general case, to run function A after function B, one writes a controller routine that first calls one, then calls the other:
For your case, where you have an execution time limit to deal with that would otherwise kill they execution of one of your functions and prevent the rest from running, you need to write a scheduling routine that makes use of Apps Scripts
ScriptApp
class. You have a number of ways to do this, from scheduling the first with a set interval trigger and using each function to tell Google when to run the next function, rather than to run the next function, or using a script property to indicate the next function which be run, to manually running one and having the last one set up a call for the first.Example of chaining:
Property method:
If you implement a solution that chains functions (vs. one that uses a property to indicate which to run), you will want to make sure you delete previous triggers to prevent the trigger count from growing endlessly.