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

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

Issue 2035793004: [Findit] Updating try job dashboard to display in queue and execution times (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 4 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 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 from datetime import datetime 4 from datetime import datetime
5 from datetime import time 5 from datetime import time
6 from datetime import timedelta 6 from datetime import timedelta
7 7
8 from common.base_handler import BaseHandler 8 from common.base_handler import BaseHandler
9 from common.base_handler import Permission 9 from common.base_handler import Permission
10 from model.wf_try_job_data import WfTryJobData 10 from model.wf_try_job_data import WfTryJobData
11 11
12 12
13 # TODO(lijeffrey): Refactor formatting functions into a separate module that 13 # TODO(lijeffrey): Refactor formatting functions into a separate module that
14 # can be shared across Findit. 14 # can be shared across Findit.
15 def _RemoveMicrosecondsFromDelta(delta): 15 def _RemoveMicrosecondsFromDelta(delta):
16 """Returns a timedelta object without microseconds based on delta.""" 16 """Returns a timedelta object without microseconds based on delta."""
17 return delta - timedelta(microseconds=delta.microseconds) 17 return delta - timedelta(microseconds=delta.microseconds)
18 18
19 19
20 def _FormatDuration(start_time, end_time):
21 return _FormatTimedelta(_GetTimeDelta(start_time, end_time))
22
23
24 def _GetTimeDelta(start_time, end_time):
25 if not start_time or not end_time:
26 return timedelta(0)
stgao 2016/06/02 22:13:57 Should we do "N/A" instead if any time is None?
lijeffrey 2016/06/03 03:18:27 Done.
27 return end_time - start_time
28
29
20 def _FormatTimedelta(delta): 30 def _FormatTimedelta(delta):
21 if not delta:
22 return None
23 hours, remainder = divmod(delta.seconds, 3600) 31 hours, remainder = divmod(delta.seconds, 3600)
24 minutes, seconds = divmod(remainder, 60) 32 minutes, seconds = divmod(remainder, 60)
25 return '%02d:%02d:%02d' % (hours, minutes, seconds) 33 return '%02d:%02d:%02d' % (hours, minutes, seconds)
26 34
27 35
28 def _FormatDatetime(date): 36 def _FormatDatetime(date):
29 if not date: 37 if not date:
30 return None 38 return None
31 else: 39 else:
32 return date.strftime('%Y-%m-%d %H:%M:%S UTC') 40 return date.strftime('%Y-%m-%d %H:%M:%S UTC')
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 'builder_name': try_job_data.builder_name, 78 'builder_name': try_job_data.builder_name,
71 'build_number': try_job_data.build_number, 79 'build_number': try_job_data.build_number,
72 'try_job_type': try_job_data.try_job_type, 80 'try_job_type': try_job_data.try_job_type,
73 'start_time': _FormatDatetime(try_job_data.start_time), 81 'start_time': _FormatDatetime(try_job_data.start_time),
74 'request_time': _FormatDatetime(try_job_data.request_time), 82 'request_time': _FormatDatetime(try_job_data.request_time),
75 'try_job_url': try_job_data.try_job_url 83 'try_job_url': try_job_data.try_job_url
76 } 84 }
77 85
78 if not try_job_data.end_time and not try_job_data.error: 86 if not try_job_data.end_time and not try_job_data.error:
79 try_job_display_data['elapsed_time'] = ( 87 try_job_display_data['elapsed_time'] = (
80 _FormatTimedelta(datetime.utcnow() - try_job_data.request_time) if 88 _FormatDuration(try_job_data.request_time, datetime.utcnow()) if
81 try_job_data.request_time else None) 89 try_job_data.request_time else None)
82 90
83 try_job_display_data['status'] = ( 91 try_job_display_data['status'] = (
84 'running' if try_job_data.start_time else 'pending') 92 'running' if try_job_data.start_time else 'pending')
85 try_jobs_in_progress.append(try_job_display_data) 93 try_jobs_in_progress.append(try_job_display_data)
86 elif try_job_data.error: 94 elif try_job_data.error:
87 try_job_display_data['error'] = try_job_data.error['message'] 95 try_job_display_data['error'] = try_job_data.error['message']
88 # It is possible end_time is not available if the error was timeout. 96 # It is possible end_time is not available if the error was timeout.
89 try_job_display_data['end_time'] = _FormatDatetime( 97 try_job_display_data['execution_time'] = _FormatDuration(
90 try_job_data.end_time) 98 try_job_data.start_time, try_job_data.end_time)
99 try_job_display_data['in_queue_time'] = _FormatDuration(
stgao 2016/06/02 22:13:57 nit: "pending time"? Same for UI.
lijeffrey 2016/06/03 03:18:27 Done.
100 try_job_data.request_time, try_job_data.start_time)
91 try_jobs_with_error.append(try_job_display_data) 101 try_jobs_with_error.append(try_job_display_data)
92 else: 102 else:
93 try_job_display_data['culprit_found'] = bool(try_job_data.culprits) 103 try_job_display_data['culprit_found'] = bool(try_job_data.culprits)
94 try_job_display_data['end_time'] = ( 104 try_job_display_data['execution_time'] = _FormatDuration(
95 _FormatDatetime(try_job_data.end_time)) 105 try_job_data.start_time, try_job_data.end_time)
106 try_job_display_data['in_queue_time'] = _FormatDuration(
107 try_job_data.request_time, try_job_data.start_time)
96 successfully_completed_try_jobs.append(try_job_display_data) 108 successfully_completed_try_jobs.append(try_job_display_data)
97 109
98 data = { 110 data = {
99 'start_date': _FormatDatetime(start_date), 111 'start_date': _FormatDatetime(start_date),
100 'end_date': _FormatDatetime(end_date), 112 'end_date': _FormatDatetime(end_date),
101 'try_jobs_in_progress': try_jobs_in_progress, 113 'try_jobs_in_progress': try_jobs_in_progress,
stgao 2016/06/02 22:16:33 Sorted by reverse of start time? Same for the oth
lijeffrey 2016/06/03 03:18:27 Since start time may not always be available, we c
stgao 2016/06/03 06:36:04 sg. But why #79 still sort by start_time?
102 'try_jobs_with_error': try_jobs_with_error, 114 'try_jobs_with_error': try_jobs_with_error,
103 'successfully_completed_try_jobs': successfully_completed_try_jobs 115 'successfully_completed_try_jobs': successfully_completed_try_jobs
104 } 116 }
105 117
106 return { 118 return {
107 'template': 'try_job_dashboard.html', 119 'template': 'try_job_dashboard.html',
108 'data': data 120 'data': data
109 } 121 }
OLDNEW
« no previous file with comments | « no previous file | appengine/findit/templates/try_job_dashboard.html » ('j') | appengine/findit/templates/try_job_dashboard.html » ('J')

Powered by Google App Engine
This is Rietveld 408576698