Google Apps Script has a 6 minute runtime limit, which can get frustrating when you're trying to do something complicated. To manage this limitation, I've written a short code snippet. It does the following:
  1. Record the beginning time of execution, when the script first starts up.
  2. Check for resume data that has been stored in the cache.
    1. If it exists, this will indicate where the script should resume. If it doesn't exist, the script will assume that it should start at the beginning.
  3. Enter a do - while loop.
  4. Within the loop, complete one iteration of whatever your code is trying to do.
  5. Record the current time.
  6. Check for one of two things:
    1. Either the script will finish iterating, or
    2. the current time will be more than 5 minutes greater than when the script began execution.
  7. If the script has finished, the code will simply exit.
  8. However, if it hasn't finished, but it's running out of runtime, the script will store data in the cache, then set a trigger to run itself again in two minutes.
        If you want to use a similar approach in your own code, you're welcome to borrow as much or as little from the code below. Please remember to use the appropriate cache and properties service, as explained in the comments. Basically, if your script will only be run by one person, then the script properties & cache are fine. However, if you're using the same code in multiple documents, the document properties and cache would be more appropriate. Finally, if you're letting other users use your code, and you want to store information unique to each user, then you'd want to use the user properties and cache.

The gadget spec URL could not be found