Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 NOT_AVAILABLE = 'N/A' | |
| 14 | |
| 15 | |
| 13 # TODO(lijeffrey): Refactor formatting functions into a separate module that | 16 # TODO(lijeffrey): Refactor formatting functions into a separate module that |
| 14 # can be shared across Findit. | 17 # can be shared across Findit. |
| 15 def _RemoveMicrosecondsFromDelta(delta): | 18 def _RemoveMicrosecondsFromDelta(delta): |
| 16 """Returns a timedelta object without microseconds based on delta.""" | 19 """Returns a timedelta object without microseconds based on delta.""" |
| 17 return delta - timedelta(microseconds=delta.microseconds) | 20 return delta - timedelta(microseconds=delta.microseconds) |
| 18 | 21 |
| 19 | 22 |
| 23 def _FormatDuration(start_time, end_time): | |
| 24 return _FormatTimedelta(_GetTimeDelta(start_time, end_time)) | |
| 25 | |
| 26 | |
| 27 def _GetTimeDelta(start_time, end_time): | |
| 28 if not start_time or not end_time: | |
|
stgao
2016/06/03 06:36:04
Should this be moved to #24 above and get rid of #
lijeffrey
2016/06/03 19:40:47
Done.
| |
| 29 return NOT_AVAILABLE | |
| 30 return end_time - start_time | |
| 31 | |
| 32 | |
| 20 def _FormatTimedelta(delta): | 33 def _FormatTimedelta(delta): |
| 21 if not delta: | 34 if delta == NOT_AVAILABLE: |
| 22 return None | 35 return NOT_AVAILABLE |
| 36 | |
| 23 hours, remainder = divmod(delta.seconds, 3600) | 37 hours, remainder = divmod(delta.seconds, 3600) |
| 24 minutes, seconds = divmod(remainder, 60) | 38 minutes, seconds = divmod(remainder, 60) |
| 25 return '%02d:%02d:%02d' % (hours, minutes, seconds) | 39 return '%02d:%02d:%02d' % (hours, minutes, seconds) |
| 26 | 40 |
| 27 | 41 |
| 28 def _FormatDatetime(date): | 42 def _FormatDatetime(date): |
| 29 if not date: | 43 if not date: |
| 30 return None | 44 return None |
| 31 else: | 45 else: |
| 32 return date.strftime('%Y-%m-%d %H:%M:%S UTC') | 46 return date.strftime('%Y-%m-%d %H:%M:%S UTC') |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 53 try_job_query = WfTryJobData.query( | 67 try_job_query = WfTryJobData.query( |
| 54 WfTryJobData.request_time >= start_date, | 68 WfTryJobData.request_time >= start_date, |
| 55 WfTryJobData.request_time < end_date) | 69 WfTryJobData.request_time < end_date) |
| 56 else: # pragma: no cover | 70 else: # pragma: no cover |
| 57 # If no start date specified, then get everything up until end_date. | 71 # If no start date specified, then get everything up until end_date. |
| 58 start_date = None | 72 start_date = None |
| 59 try_job_query = WfTryJobData.query( | 73 try_job_query = WfTryJobData.query( |
| 60 WfTryJobData.request_time < end_date) | 74 WfTryJobData.request_time < end_date) |
| 61 | 75 |
| 62 try_job_data_list = try_job_query.fetch() | 76 try_job_data_list = try_job_query.fetch() |
| 77 | |
| 78 # Sort try job data list by most recent request first. | |
| 79 try_job_data_list.sort(key=lambda x: x.start_time, reverse=True) | |
| 80 | |
| 63 try_jobs_in_progress = [] | 81 try_jobs_in_progress = [] |
| 64 try_jobs_with_error = [] | 82 try_jobs_with_error = [] |
| 65 successfully_completed_try_jobs = [] | 83 successfully_completed_try_jobs = [] |
| 66 | 84 |
| 67 for try_job_data in try_job_data_list: | 85 for try_job_data in try_job_data_list: |
| 68 try_job_display_data = { | 86 try_job_display_data = { |
| 69 'master_name': try_job_data.master_name, | 87 'master_name': try_job_data.master_name, |
| 70 'builder_name': try_job_data.builder_name, | 88 'builder_name': try_job_data.builder_name, |
| 71 'build_number': try_job_data.build_number, | 89 'build_number': try_job_data.build_number, |
| 72 'try_job_type': try_job_data.try_job_type, | 90 'try_job_type': try_job_data.try_job_type, |
| 73 'start_time': _FormatDatetime(try_job_data.start_time), | 91 'pending_time': _FormatDuration( |
| 92 try_job_data.request_time, try_job_data.start_time), | |
| 74 'request_time': _FormatDatetime(try_job_data.request_time), | 93 'request_time': _FormatDatetime(try_job_data.request_time), |
| 75 'try_job_url': try_job_data.try_job_url | 94 'try_job_url': try_job_data.try_job_url |
| 76 } | 95 } |
| 77 | 96 |
| 78 if not try_job_data.end_time and not try_job_data.error: | 97 if not try_job_data.end_time and not try_job_data.error: |
| 79 try_job_display_data['elapsed_time'] = ( | 98 try_job_display_data['elapsed_time'] = ( |
| 80 _FormatTimedelta(datetime.utcnow() - try_job_data.request_time) if | 99 _FormatDuration(try_job_data.request_time, datetime.utcnow()) if |
| 81 try_job_data.request_time else None) | 100 try_job_data.request_time else None) |
| 82 | |
| 83 try_job_display_data['status'] = ( | 101 try_job_display_data['status'] = ( |
| 84 'running' if try_job_data.start_time else 'pending') | 102 'running' if try_job_data.start_time else 'pending') |
| 85 try_jobs_in_progress.append(try_job_display_data) | 103 try_jobs_in_progress.append(try_job_display_data) |
| 86 elif try_job_data.error: | 104 elif try_job_data.error: |
| 87 try_job_display_data['error'] = try_job_data.error['message'] | 105 try_job_display_data['error'] = try_job_data.error['message'] |
| 88 # It is possible end_time is not available if the error was timeout. | 106 # It is possible end_time is not available if the error was timeout. |
| 89 try_job_display_data['end_time'] = _FormatDatetime( | 107 try_job_display_data['execution_time'] = _FormatDuration( |
| 90 try_job_data.end_time) | 108 try_job_data.start_time, try_job_data.end_time) |
| 91 try_jobs_with_error.append(try_job_display_data) | 109 try_jobs_with_error.append(try_job_display_data) |
| 92 else: | 110 else: |
| 93 try_job_display_data['culprit_found'] = bool(try_job_data.culprits) | 111 try_job_display_data['culprit_found'] = bool(try_job_data.culprits) |
| 94 try_job_display_data['end_time'] = ( | 112 try_job_display_data['execution_time'] = _FormatDuration( |
| 95 _FormatDatetime(try_job_data.end_time)) | 113 try_job_data.start_time, try_job_data.end_time) |
| 96 successfully_completed_try_jobs.append(try_job_display_data) | 114 successfully_completed_try_jobs.append(try_job_display_data) |
| 97 | 115 |
| 98 data = { | 116 data = { |
| 99 'start_date': _FormatDatetime(start_date), | 117 'start_date': _FormatDatetime(start_date), |
| 100 'end_date': _FormatDatetime(end_date), | 118 'end_date': _FormatDatetime(end_date), |
| 101 'try_jobs_in_progress': try_jobs_in_progress, | 119 'try_jobs_in_progress': try_jobs_in_progress, |
| 102 'try_jobs_with_error': try_jobs_with_error, | 120 'try_jobs_with_error': try_jobs_with_error, |
| 103 'successfully_completed_try_jobs': successfully_completed_try_jobs | 121 'successfully_completed_try_jobs': successfully_completed_try_jobs |
| 104 } | 122 } |
| 105 | 123 |
| 106 return { | 124 return { |
| 107 'template': 'try_job_dashboard.html', | 125 'template': 'try_job_dashboard.html', |
| 108 'data': data | 126 'data': data |
| 109 } | 127 } |
| OLD | NEW |