Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: globals/get_browser_versions.py

Issue 29321081: Issue 2722 - Don't report persistent errors with external APIs more often than once a day (Closed)
Patch Set: Created June 25, 2015, 12:52 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import re 1 import re
2 import os 2 import os
3 import sys 3 import sys
4 import json 4 import json
5 import urllib 5 import urllib
6 import errno 6 import errno
7 import logging 7 import logging
8 import time 8 import time
9 from xml.dom import minidom 9 from xml.dom import minidom
10 10
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 raise 190 raise
191 persistent_cache = {} 191 persistent_cache = {}
192 192
193 cached_versions = persistent_cache.get(browser) 193 cached_versions = persistent_cache.get(browser)
194 now = time.mktime(time.gmtime()) 194 now = time.mktime(time.gmtime())
195 if exc_info: 195 if exc_info:
196 if not cached_versions: 196 if not cached_versions:
197 raise exc_info[0], exc_info[1], exc_info[2] 197 raise exc_info[0], exc_info[1], exc_info[2]
198 198
199 versions = cached_versions 199 versions = cached_versions
200 if now - versions['timestamp'] > 60*60*2: 200 if now > versions['fail_silently_until']:
201 versions['fail_silently_until'] = now + 60*60*24
201 logging.warning('Failed to get %s versions, falling back to ' 202 logging.warning('Failed to get %s versions, falling back to '
202 'cached versions', browser, exc_info=exc_info) 203 'cached versions', browser, exc_info=exc_info)
203 else: 204 else:
204 # Determine previous version: If we recorded the version before and it 205 # Determine previous version: If we recorded the version before and it
205 # changed since then, the old current version becomes the new previous 206 # changed since then, the old current version becomes the new previous
206 # version. If the version didn't change, use the cached previous version. 207 # version. If the version didn't change, use the cached previous version.
207 current = versions['current'] 208 current = versions['current']
208 previous = None 209 previous = None
209 if cached_versions: 210 if cached_versions:
210 cached_current = cached_versions['current'] 211 cached_current = cached_versions['current']
211 if cached_current != current: 212 if cached_current != current:
212 previous = cached_current 213 previous = cached_current
213 else: 214 else:
214 previous = cached_versions['previous'] 215 previous = cached_versions['previous']
215 versions['previous'] = previous 216 versions['previous'] = previous
216 217
217 # Remove duplicates from unreleased versions. Occasionally, 218 # Remove duplicates from unreleased versions. Occasionally,
218 # different channels are on the same version, but we want 219 # different channels are on the same version, but we want
219 # to list each version only once. 220 # to list each version only once.
220 versions['unreleased'] = sorted( 221 versions['unreleased'] = sorted(
221 set(versions['unreleased']) - set(re.sub(r'(\.0*)+$', '', ver) for ver i n (current, previous) if ver), 222 set(versions['unreleased']) - set(re.sub(r'(\.0*)+$', '', ver) for ver i n (current, previous) if ver),
222 key=key_by_version 223 key=key_by_version
223 ) 224 )
224 225
225 versions['timestamp'] = now 226 versions['fail_silently_until'] = now + 60*60*2
226 persistent_cache[browser] = versions 227 persistent_cache[browser] = versions
227 file.seek(0) 228
228 json.dump(persistent_cache, file) 229 file.seek(0)
229 file.truncate() 230 json.dump(persistent_cache, file)
231 file.truncate()
230 232
231 if not versions['previous']: 233 if not versions['previous']:
232 logging.warning("Couldn't determine previous browser version, " 234 logging.warning("Couldn't determine previous browser version, "
233 'please set %s.previous in %s', browser, filename) 235 'please set %s.previous in %s', browser, filename)
234 236
235 cache[browser] = versions 237 cache[browser] = versions
236 return versions 238 return versions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld