Sunday, January 1, 2012

Documents List API

Google have recently added a new section to the Google Documents List API documentation, titled Handling AP errors. A number of developers in the forum have asked what to do when certain requests cause errors, and this documentation responds to their general need for better information. This new documentation details all errors and the scenarios that cause them. We strongly recommend that both new and advanced Google Documents List API developers read the section thoroughly. An important technique described in the new docs is exponential backoff. Exponential backoff helps clients to automatically retry requests that fail for intermittent reasons. For example, an application might make too many requests to the API in a short period of time, resulting in HTTP 503 responses. In cases like this, it makes sense for API clients to automatically retry the requests until they succeed. Exponential backoff can be implemented in all of the Google Data API client libraries. An example in Python follows:
import random
import time

def GetResourcesWithExponentialBackoff(client):
  """Gets all of the resources for the authorized user

    client: authorized for a user.
  Returns: representing Resources found in request.
  for n in range(0, 5):
      response = client.GetResources()
      return response
      time.sleep((2 ** n) + (random.randint(0, 1000) / 1000))
  print "There has been an error, the request never succeeded."
  return None
We strongly recommend developers take about 30 minutes and update applications to use exponential backoff. For help doing this, please read the documentation and post in the forum if you have any questions.

No comments:

Post a Comment

Share This: