Last active
November 16, 2017 13:35
-
-
Save bennettscience/dda1b3c730ede7d45a6518046cb88c13 to your computer and use it in GitHub Desktop.
Prevent script timeouts in Google Apps Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isTimeUp_(starttime) { | |
var now = new Date(); | |
return now.getTime() - starttime.getTime() > 270000; // 4.5 minutes | |
} | |
// Set the start time outside the loop | |
var starttime = new Date(); | |
// Inside your function, check the time and break to prevent failure mid-loop | |
for(var i=0; i<data.length; i++) { | |
if(isTimeUp_(starttime)) { | |
break; | |
} | |
// continue loop | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment