Beat the Clock! Dodging the Maximum Script Runtime in Google Apps Script ⏲️

Dmitry Kostyuk
Geek Culture
Published in
12 min readAug 16, 2021

--

What’s the Threshold ?

Google Apps Script is an amazing language that can automate a lot of your work. However, working with GAS also means that you have to learn to live with its built-in limitations and quotas.

One such quota is the total script runtime. It’s limited to six minutes on free accounts and thirty minutes on corporate accounts. After the above threshold is reached, the execution is interrupted with the following error message:

Sometimes this is not enough. I have experienced that the time required to complete tasks like copying or even simply listing files on a drive or in a directory can be quite long. Merging hundreds or thousands of documents can also take longer than both thresholds.

Now let’s look into how we can build a solution.

The full source code is available on GitHub.

The Underlying Principle

The first thing you must do is stop script execution before the threshold runs out. Therefore, you need to have a means of timing your execution time and exiting gracefully.

You then need to create a trigger to restart the execution. This way, you automatically get another six or thirty minutes…

--

--