Deduper Resolve Errors, Exponential backoff

Remove Duplicate files in Google Drive에 이어서

Apps script로 구글 드라이브 API를 호출하는데 구글 서버 오류가 발생하면 그냥 종료합니다.

앱 사용자가 로그 스프레드시트를 보고 중단된 이유에 따라 Find 버튼을 클릭할 수 있습니다.

서버 오류를 처리하기 위해서 ...



Error

GoogleJsonResponseException
다음 오류로 인해 drive.files.list API를 호출하지 못했습니다. Internal Error


GoogleJsonResponseException
다음 오류로 인해 drive.parents.insert API를 호출하지 못했습니다. Backend Error


오류를 해결하기 위해서 찾아보니 Exponential backoff를 권장합니다.



Resolve errors

https://developers.google.com/drive/api/v2/handle-errors


500: Backend error
An unexpected error occurred while processing the request.

Retry failed requests to resolve errors


https://developers.google.com/drive/api/v3/handle-errors#exponential-backoff

You can periodically retry a failed request over an increasing amount of time to handle errors related to rate limits, network volume, or response time. For example, you might retry a failed request after one second, then after two seconds, and then after four seconds. This method, called exponential backoff, improves bandwidth usage and maximizes throughput of requests in concurrent environments.

Start retry periods at least one second after the error. If the attempted request introduces a change, such as a create request, add a check to make sure nothing is duplicated. Some errors, such as invalid authorization credentials or "file not found" errors, aren’t resolved by retrying the request.


Upload Sample


https://github.com/gsuitedevs/drive-utils/tree/master/upload

Sample code for uploading files directly with vanilla Javascript (XHR/CORS). Try the live version and drag & drop files to upload them to Google Drive.


https://github.com/gsuitedevs/drive-utils/blob/master/upload/upload.js

/**
 * Helper for implementing retries with backoff. Initial retry
 * delay is 1 second, increasing by 2x (+jitter) for subsequent retries
 *
 * @constructor
 */
var RetryHandler = function() {
  this.interval = 1000; // Start at one second
  this.maxInterval = 60 * 1000; // Don't wait longer than a minute 
};

댓글

이 블로그의 인기 게시물

Files in Google Drive

Writes Apps Script errors in this spreadsheet.

Copy to shared drives app