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

Side by Side Diff: app.py

Issue 11934003: Put latest_rev data in datastore instead of memcache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/chromium-build
Patch Set: Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« 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 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from __future__ import with_statement 5 from __future__ import with_statement
6 6
7 import datetime 7 import datetime
8 import json 8 import json
9 import logging 9 import logging
10 import os 10 import os
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 205
206 get_and_cache_rowdata takes a localpath which is used to fetch data from the 206 get_and_cache_rowdata takes a localpath which is used to fetch data from the
207 cache. If the data is present, then we have all of the data we need and we 207 cache. If the data is present, then we have all of the data we need and we
208 return early. 208 return early.
209 209
210 Otherwise, we need to fetch the row object and set up the row data. 210 Otherwise, we need to fetch the row object and set up the row data.
211 211
212 Here we assume localpath is already unquoted. 212 Here we assume localpath is already unquoted.
213 """ 213 """
214 row_data = get_data_from_cache(localpath) 214 row_data = get_data_from_cache(localpath)
215 if row_data: 215 if row_data and type(row_data) == type({}):
Ryan Tseng 2013/01/15 22:05:32 In what cases would it not be a dict?
agable 2013/01/15 22:09:41 The latest_rev row used to be stored in memcache a
216 return row_data 216 return row_data
217 row = Row.all().filter('localpath =', localpath).get() 217 row = Row.all().filter('localpath =', localpath).get()
Ryan Tseng 2013/01/15 22:05:32 How many entires can we expect this to return?
agable 2013/01/15 22:09:41 Exactly one. It is being replaced by row = Row.get
218 if not row: 218 if not row:
219 logging.error('get_and_cache_rowdata(\'%s\'): no matching localpath in ' 219 logging.error('get_and_cache_rowdata(\'%s\'): no matching localpath in '
220 'datastore' % localpath) 220 'datastore' % localpath)
221 return {} 221 return {}
222 row_data = {} 222 row_data = {}
223 row_data['rev'] = row.revision 223 row_data['rev'] = row.revision
224 row_data['name'] = row.name 224 row_data['name'] = row.name
225 row_data['status'] = row.status 225 row_data['status'] = row.status
226 row_data['comment'] = row.comment 226 row_data['comment'] = row.comment
227 row_data['details'] = row.details 227 row_data['details'] = row.details
(...skipping 19 matching lines...) Expand all
247 row.revision = row_data['rev'] 247 row.revision = row_data['rev']
248 row.name = row_data['name'] 248 row.name = row_data['name']
249 row.status = row_data['status'] 249 row.status = row_data['status']
250 row.comment = row_data['comment'] 250 row.comment = row_data['comment']
251 row.details = row_data['details'] 251 row.details = row_data['details']
252 # E1103:967,4:save_row.tx_row: Instance of 'list' has no 'put' member 252 # E1103:967,4:save_row.tx_row: Instance of 'list' has no 'put' member
253 # (but some types could not be inferred) 253 # (but some types could not be inferred)
254 # pylint: disable=E1103 254 # pylint: disable=E1103
255 row.put() 255 row.put()
256 db.run_in_transaction(tx_row, row_key) 256 db.run_in_transaction(tx_row, row_key)
257 prev_rev = memcache.get(key='latest_rev')
258 if (rev_number > prev_rev):
259 memcache.set(key='latest_rev', value=rev_number)
260 put_data_into_cache(localpath, row_data) 257 put_data_into_cache(localpath, row_data)
261 logging.info('Saved and cached row with localpath %s' % localpath) 258 logging.info('Saved and cached row with localpath %s' % localpath)
259 # Update latest_rev in datastore & cache, or create it if it doesn't exist.
260 prev_rev = get_and_cache_rowdata('latest_rev')
261 if not prev_rev or rev_number > prev_rev['rev_number']:
262 latest_rev_row = {
263 'rev_number': rev_number,
264 'fetch_timestamp': datetime.datetime.now(),
265 'rev': None,
266 'name': None,
267 'status': None,
268 'comment': None,
269 'details': None,
270 }
271 save_row(latest_rev_row, 'latest_rev')
262 272
263 273
264 ########## 274 ##########
265 # ConsoleData class definition and related functions. 275 # ConsoleData class definition and related functions.
266 ########## 276 ##########
267 class ConsoleData(object): 277 class ConsoleData(object):
268 def __init__(self): 278 def __init__(self):
269 self.row_orderedkeys = [] 279 self.row_orderedkeys = []
270 self.row_data = {} 280 self.row_data = {}
271 281
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 # AKA postfetch and postsave functions/handlers. 391 # AKA postfetch and postsave functions/handlers.
382 ########## 392 ##########
383 def console_merger(localpath, remoteurl, page_data, 393 def console_merger(localpath, remoteurl, page_data,
384 masters_to_merge=None, num_rows_to_merge=None): 394 masters_to_merge=None, num_rows_to_merge=None):
385 masters_to_merge = masters_to_merge or DEFAULT_MASTERS_TO_MERGE 395 masters_to_merge = masters_to_merge or DEFAULT_MASTERS_TO_MERGE
386 num_rows_to_merge = num_rows_to_merge or 25 396 num_rows_to_merge = num_rows_to_merge or 25
387 mergedconsole = ConsoleData() 397 mergedconsole = ConsoleData()
388 surroundings = get_and_cache_pagedata('surroundings') 398 surroundings = get_and_cache_pagedata('surroundings')
389 merged_page = BeautifulSoup(surroundings['content']) 399 merged_page = BeautifulSoup(surroundings['content'])
390 merged_tag = merged_page.find('table', 'ConsoleData') 400 merged_tag = merged_page.find('table', 'ConsoleData')
391 latest_rev = int(memcache.get(key='latest_rev')) 401 latest_rev = int(get_and_cache_rowdata('latest_rev')['rev_number'])
392 if not latest_rev: 402 if not latest_rev:
393 logging.error('console_merger(\'%s\', \'%s\', \'%s\'): cannot get latest ' 403 logging.error('console_merger(\'%s\', \'%s\', \'%s\'): cannot get latest '
394 'revision number.' % ( 404 'revision number.' % (
395 localpath, remoteurl, page_data)) 405 localpath, remoteurl, page_data))
396 return 406 return
397 fetch_timestamp = datetime.datetime.now() 407 fetch_timestamp = datetime.datetime.now()
398 for master in masters_to_merge: 408 for master in masters_to_merge:
399 # Fetch the summary one-box-per-builder for the master. 409 # Fetch the summary one-box-per-builder for the master.
400 # If we don't get it, something is wrong, skip the master entirely. 410 # If we don't get it, something is wrong, skip the master entirely.
401 master_summary = get_and_cache_pagedata('%s/console/summary' % master) 411 master_summary = get_and_cache_pagedata('%s/console/summary' % master)
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 # LKGR JSON. 1184 # LKGR JSON.
1175 { 1185 {
1176 'remoteurl': 1186 'remoteurl':
1177 ('http://build.chromium.org/p/chromium.lkgr/json/builders/Linux%20x64/' 1187 ('http://build.chromium.org/p/chromium.lkgr/json/builders/Linux%20x64/'
1178 'builds/-1?as_text=1'), 1188 'builds/-1?as_text=1'),
1179 'localpath': 1189 'localpath':
1180 'chromium.lkgr/json/builders/Linux%20x64/builds/-1/as_text=1.json', 1190 'chromium.lkgr/json/builders/Linux%20x64/builds/-1/as_text=1.json',
1181 'maxage': 2*60, # 2 mins 1191 'maxage': 2*60, # 2 mins
1182 }, 1192 },
1183 ] 1193 ]
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 408576698