Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2065)

Unified Diff: chrome/common/extensions/docs/server2/url_fetcher_appengine.py

Issue 1151283007: Docserver overhaul: Gitiles away from me. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove inform_users template to fix presubmit failure (it's now a redirect) Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/url_fetcher_appengine.py
diff --git a/chrome/common/extensions/docs/server2/url_fetcher_appengine.py b/chrome/common/extensions/docs/server2/url_fetcher_appengine.py
new file mode 100644
index 0000000000000000000000000000000000000000..f5080aeb3f930b9b874b2bf978ec4088ff9813f4
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/url_fetcher_appengine.py
@@ -0,0 +1,43 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import google.appengine.api.urlfetch as urlfetch
+import logging
+import time
+import traceback
+
+from future import Future
+from url_fetcher import UrlFetcher
+
+
+_MAX_RETRIES = 5
+_RETRY_DELAY_SECONDS = 30
+
+
+class UrlFetcherAppengine(UrlFetcher):
+ """An implementation of UrlFetcher which uses the GAE urlfetch API to
+ execute URL fetches.
+ """
+ def __init__(self):
+ self._retries_left = _MAX_RETRIES
+
+ def FetchImpl(self, url, headers):
+ return urlfetch.fetch(url, deadline=20, headers=headers)
+
+ def FetchAsyncImpl(self, url, headers):
+ def process_result(result):
+ if result.status_code == 429:
+ if self._retries_left == 0:
+ logging.error('Still throttled. Giving up.')
+ return result
+ self._retries_left -= 1
+ logging.info('Throttled. Trying again in %s seconds.' %
+ _RETRY_DELAY_SECONDS)
+ time.sleep(_RETRY_DELAY_SECONDS)
+ return self.FetchAsync(url, username, password, access_token).Get()
+ return result
+
+ rpc = urlfetch.create_rpc(deadline=20)
+ urlfetch.make_fetch_call(rpc, url, headers=headers)
+ return Future(callback=lambda: process_result(rpc.get_result()))
« no previous file with comments | « chrome/common/extensions/docs/server2/url_fetcher.py ('k') | chrome/common/extensions/docs/server2/url_fetcher_fake.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698