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

Unified Diff: dashboard/dashboard/utils.py

Issue 1566013002: Add support for bisect bots to post results to dashboard. (Closed) Base URL: https://github.com/catapult-project/catapult.git@master
Patch Set: rebase Created 4 years, 10 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
« no previous file with comments | « dashboard/dashboard/update_bug_with_results_test.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dashboard/dashboard/utils.py
diff --git a/dashboard/dashboard/utils.py b/dashboard/dashboard/utils.py
index ba307f2b377c30d01aa58f013c617b2c8ac79aae..c9f6db3005a0d462e93358ba4f13cc3084c16f16 100644
--- a/dashboard/dashboard/utils.py
+++ b/dashboard/dashboard/utils.py
@@ -14,6 +14,7 @@ import time
from apiclient import discovery
from google.appengine.api import urlfetch
+from google.appengine.api import urlfetch_errors
from google.appengine.api import users
from google.appengine.ext import ndb
from oauth2client.client import GoogleCredentials
@@ -338,3 +339,33 @@ def Validate(expected, actual):
elif not IsValidType(expected, actual):
raise ValueError('Invalid type. Expected: %s. Actual: %s.' %
(expected, actual_type))
+
+
+def FetchURL(request_url, skip_status_code=False):
+ """Wrapper around URL fetch service to make request.
+
+ Args:
+ request_url: URL of request.
+ skip_status_code: Skips return code check when True, default is False.
+
+ Returns:
+ Response object return by URL fetch, otherwise None when there's an error.
+ """
+ logging.info('URL being fetched: ' + request_url)
+ try:
+ response = urlfetch.fetch(request_url)
+ except urlfetch_errors.DeadlineExceededError:
+ logging.error('Deadline exceeded error checking %s', request_url)
+ return None
+ except urlfetch_errors.DownloadError as err:
+ # DownloadError is raised to indicate a non-specific failure when there
+ # was not a 4xx or 5xx status code.
+ logging.error(err)
+ return None
+ if skip_status_code:
+ return response
+ elif response.status_code != 200:
+ logging.error(
+ 'ERROR %s checking %s', response.status_code, request_url)
+ return None
+ return response
« no previous file with comments | « dashboard/dashboard/update_bug_with_results_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698