I’ve noticed occasionally that my Drive SDK calls fail periodically with a 500 error, retrying the request usually fixes the error immediately. Looking at the Google documentation, its recommended to use the exponential back off technique, I wrote my own implementation which works fine, however while debugging I happened to bump into the interface BackOffPolicy, with more investigation I even found the implementation ExponentialBackOffPolicy.
So instead of managing this myself, I thought best to remove my implementation and let the SDK do it for me. The backoff policy can (from my knowledge) be set with a built HTTP request, so its quite easy to use when manually building requests or when using batch requests, however I cannot seem to find the easiest place to inject this when using the core SDK, for example, if I want to set a backoff policy for:
drive.files().get(id).execute();
I cannot do something like:
drive.files().get(id)
.setBackOffPolicy(new ExponentialBackOffPolicy())
.execute();
I would need to do this:
drive.files().get(id)
.buildHttpRequest()
.setBackOffPolicy(new ExponentialBackOffPolicy())
.execute();
However if I do that, then I would also need to reproduce the parsing logic of the execute method of Drive.Files.Get and convert the result to a File object which is obviously not an ideal approach. Is there an easier way to “generically” add this to the request or perhaps a way to set a default back off policy for all requests?
If not, perhaps this could be introduced into a future version of the Drive SDK?
Thanks,
David
AFAIK Google made Exponential Backoff is only used when downloading or uploading content in the drive Java API. You need your own implementation for the other requests.
What I did to implement it for any request is wrap a Callable executing once the request and letting the wrapper class do the exception handling and repeating of the request.