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

Side by Side Diff: appengine/findit/handlers/try_job_dashboard.py

Issue 2259513003: [Findit] Display last build bucket response to try job dashboard (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Rebase Created 4 years, 4 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
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 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 from datetime import datetime 5 from datetime import datetime
5 from datetime import time 6 from datetime import time
6 from datetime import timedelta 7 from datetime import timedelta
8 import json
7 9
8 from common import time_util 10 from common import time_util
9 from common.base_handler import BaseHandler 11 from common.base_handler import BaseHandler
10 from common.base_handler import Permission 12 from common.base_handler import Permission
11 from model.wf_try_job_data import WfTryJobData 13 from model.wf_try_job_data import WfTryJobData
12 14
13 15
14 NOT_AVAILABLE = 'N/A' 16 NOT_AVAILABLE = 'N/A'
15 17
16 18
17 def _FormatDuration(start_time, end_time): 19 def _FormatDuration(start_time, end_time):
18 if not start_time or not end_time: 20 if not start_time or not end_time:
19 return NOT_AVAILABLE 21 return NOT_AVAILABLE
20 return time_util.FormatTimedelta(end_time - start_time) 22 return time_util.FormatTimedelta(end_time - start_time)
21 23
22 24
25 def _PrepareBuildbucketResponseForDisplay(buildbucket_response):
26 """Prepares a buildbucket response for display in the template.
27
28 buildbucket_response contains json inside json, which causes problems when
29 pretty printing in the corresponding template file. This function reformats
30 internal json as a dict.
31
32 Args:
33 buildbucket_response: A raw buildbucket response json object.
34
35 Returns:
36 A copy of the original buildbucket response dict, with json fields replaced
37 by dicts.
38 """
39 if buildbucket_response is None:
40 return None
41
42 new_response = {}
43
44 for key, value in buildbucket_response.iteritems():
45 if 'json' in key:
46 value = json.loads(value)
47
48 new_response[key] = value
49
50 return new_response
51
52
23 class TryJobDashboard(BaseHandler): 53 class TryJobDashboard(BaseHandler):
24 PERMISSION_LEVEL = Permission.ANYONE 54 PERMISSION_LEVEL = Permission.ANYONE
25 55
26 def HandleGet(self): 56 def HandleGet(self):
27 """Shows a list of Findit try job results and statuses in an HTML page.""" 57 """Shows a list of Findit try job results and statuses in an HTML page."""
28 midnight_today = datetime.combine(time_util.GetUTCNow(), time.min) 58 midnight_today = datetime.combine(time_util.GetUTCNow(), time.min)
29 midnight_yesterday = midnight_today - timedelta(days=1) 59 midnight_yesterday = midnight_today - timedelta(days=1)
30 midnight_tomorrow = midnight_today + timedelta(days=1) 60 midnight_tomorrow = midnight_today + timedelta(days=1)
31 61
32 start = self.request.get('start_date') 62 start = self.request.get('start_date')
(...skipping 25 matching lines...) Expand all
58 88
59 for try_job_data in try_job_data_list: 89 for try_job_data in try_job_data_list:
60 try_job_display_data = { 90 try_job_display_data = {
61 'master_name': try_job_data.master_name, 91 'master_name': try_job_data.master_name,
62 'builder_name': try_job_data.builder_name, 92 'builder_name': try_job_data.builder_name,
63 'build_number': try_job_data.build_number, 93 'build_number': try_job_data.build_number,
64 'try_job_type': try_job_data.try_job_type, 94 'try_job_type': try_job_data.try_job_type,
65 'pending_time': _FormatDuration( 95 'pending_time': _FormatDuration(
66 try_job_data.request_time, try_job_data.start_time), 96 try_job_data.request_time, try_job_data.start_time),
67 'request_time': time_util.FormatDatetime(try_job_data.request_time), 97 'request_time': time_util.FormatDatetime(try_job_data.request_time),
68 'try_job_url': try_job_data.try_job_url 98 'try_job_url': try_job_data.try_job_url,
99 'last_buildbucket_response': json.dumps(
100 _PrepareBuildbucketResponseForDisplay(
101 try_job_data.last_buildbucket_response), sort_keys=True)
69 } 102 }
70 103
71 if not try_job_data.end_time and not try_job_data.error: 104 if not try_job_data.end_time and not try_job_data.error:
72 try_job_display_data['elapsed_time'] = ( 105 try_job_display_data['elapsed_time'] = (
73 _FormatDuration(try_job_data.request_time, time_util.GetUTCNow()) if 106 _FormatDuration(try_job_data.request_time, time_util.GetUTCNow()) if
74 try_job_data.request_time else None) 107 try_job_data.request_time else None)
75 try_job_display_data['status'] = ( 108 try_job_display_data['status'] = (
76 'running' if try_job_data.start_time else 'pending') 109 'running' if try_job_data.start_time else 'pending')
77 try_jobs_in_progress.append(try_job_display_data) 110 try_jobs_in_progress.append(try_job_display_data)
78 elif try_job_data.error: 111 elif try_job_data.error:
(...skipping 13 matching lines...) Expand all
92 'end_date': time_util.FormatDatetime(end_date), 125 'end_date': time_util.FormatDatetime(end_date),
93 'try_jobs_in_progress': try_jobs_in_progress, 126 'try_jobs_in_progress': try_jobs_in_progress,
94 'try_jobs_with_error': try_jobs_with_error, 127 'try_jobs_with_error': try_jobs_with_error,
95 'successfully_completed_try_jobs': successfully_completed_try_jobs 128 'successfully_completed_try_jobs': successfully_completed_try_jobs
96 } 129 }
97 130
98 return { 131 return {
99 'template': 'try_job_dashboard.html', 132 'template': 'try_job_dashboard.html',
100 'data': data 133 'data': data
101 } 134 }
OLDNEW
« no previous file with comments | « appengine/findit/handlers/test/try_job_dashboard_test.py ('k') | appengine/findit/templates/try_job_dashboard.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698