Skip to content

Commit

Permalink
Merge pull request #3 from liamptiernan/Fix-Ping-URL-Retry-With-Backoffs
Browse files Browse the repository at this point in the history
Fixed Retry with Backoffs Error
  • Loading branch information
liamptiernan authored Jan 27, 2022
2 parents f0ad50b + d28faae commit f25dfc0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
function pingUrl(url, options, maxRetries=2) {
function pingUrl(url, options, maxRetries = 4) {
let retries = 0;
let response;

while (retries <= maxRetries) {
response = UrlFetchApp.fetch(url, options);
let code = response.getResponseCode();

if (code < 500) {
if (code < 500 || retries === maxRetries) {
break;
} else {
Logger.log(`Retrying ${url} because of possible transient error: ${code}`);
setTimeout(function() {retries++;}, Math.pow(1500,(1+(retries/10))));
Logger.log(`Retrying ${url} because of possible transient error: HTTP Code ${code}`);
Utilities.sleep(1500**(1+(retries/10)));
retries++;
}
}
return response;
Expand Down

0 comments on commit f25dfc0

Please sign in to comment.