| 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 if not start_time or not end_time: |
| 25 return NOT_AVAILABLE |
| 26 return _FormatTimedelta(end_time - start_time) |
| 27 |
| 28 |
| 20 def _FormatTimedelta(delta): | 29 def _FormatTimedelta(delta): |
| 21 if not delta: | |
| 22 return None | |
| 23 hours, remainder = divmod(delta.seconds, 3600) | 30 hours, remainder = divmod(delta.seconds, 3600) |
| 24 minutes, seconds = divmod(remainder, 60) | 31 minutes, seconds = divmod(remainder, 60) |
| 25 return '%02d:%02d:%02d' % (hours, minutes, seconds) | 32 return '%02d:%02d:%02d' % (hours, minutes, seconds) |
| 26 | 33 |
| 27 | 34 |
| 28 def _FormatDatetime(date): | 35 def _FormatDatetime(date): |
| 29 if not date: | 36 if not date: |
| 30 return None | 37 return None |
| 31 else: | 38 else: |
| 32 return date.strftime('%Y-%m-%d %H:%M:%S UTC') | 39 return date.strftime('%Y-%m-%d %H:%M:%S UTC') |
| (...skipping 20 matching lines...) Expand all Loading... |
| 53 try_job_query = WfTryJobData.query( | 60 try_job_query = WfTryJobData.query( |
| 54 WfTryJobData.request_time >= start_date, | 61 WfTryJobData.request_time >= start_date, |
| 55 WfTryJobData.request_time < end_date) | 62 WfTryJobData.request_time < end_date) |
| 56 else: # pragma: no cover | 63 else: # pragma: no cover |
| 57 # If no start date specified, then get everything up until end_date. | 64 # If no start date specified, then get everything up until end_date. |
| 58 start_date = None | 65 start_date = None |
| 59 try_job_query = WfTryJobData.query( | 66 try_job_query = WfTryJobData.query( |
| 60 WfTryJobData.request_time < end_date) | 67 WfTryJobData.request_time < end_date) |
| 61 | 68 |
| 62 try_job_data_list = try_job_query.fetch() | 69 try_job_data_list = try_job_query.fetch() |
| 70 |
| 71 # Sort try job data list by most recent request first. |
| 72 try_job_data_list.sort(key=lambda x: x.request_time, reverse=True) |
| 73 |
| 63 try_jobs_in_progress = [] | 74 try_jobs_in_progress = [] |
| 64 try_jobs_with_error = [] | 75 try_jobs_with_error = [] |
| 65 successfully_completed_try_jobs = [] | 76 successfully_completed_try_jobs = [] |
| 66 | 77 |
| 67 for try_job_data in try_job_data_list: | 78 for try_job_data in try_job_data_list: |
| 68 try_job_display_data = { | 79 try_job_display_data = { |
| 69 'master_name': try_job_data.master_name, | 80 'master_name': try_job_data.master_name, |
| 70 'builder_name': try_job_data.builder_name, | 81 'builder_name': try_job_data.builder_name, |
| 71 'build_number': try_job_data.build_number, | 82 'build_number': try_job_data.build_number, |
| 72 'try_job_type': try_job_data.try_job_type, | 83 'try_job_type': try_job_data.try_job_type, |
| 73 'start_time': _FormatDatetime(try_job_data.start_time), | 84 'pending_time': _FormatDuration( |
| 85 try_job_data.request_time, try_job_data.start_time), |
| 74 'request_time': _FormatDatetime(try_job_data.request_time), | 86 'request_time': _FormatDatetime(try_job_data.request_time), |
| 75 'try_job_url': try_job_data.try_job_url | 87 'try_job_url': try_job_data.try_job_url |
| 76 } | 88 } |
| 77 | 89 |
| 78 if not try_job_data.end_time and not try_job_data.error: | 90 if not try_job_data.end_time and not try_job_data.error: |
| 79 try_job_display_data['elapsed_time'] = ( | 91 try_job_display_data['elapsed_time'] = ( |
| 80 _FormatTimedelta(datetime.utcnow() - try_job_data.request_time) if | 92 _FormatDuration(try_job_data.request_time, datetime.utcnow()) if |
| 81 try_job_data.request_time else None) | 93 try_job_data.request_time else None) |
| 82 | |
| 83 try_job_display_data['status'] = ( | 94 try_job_display_data['status'] = ( |
| 84 'running' if try_job_data.start_time else 'pending') | 95 'running' if try_job_data.start_time else 'pending') |
| 85 try_jobs_in_progress.append(try_job_display_data) | 96 try_jobs_in_progress.append(try_job_display_data) |
| 86 elif try_job_data.error: | 97 elif try_job_data.error: |
| 87 try_job_display_data['error'] = try_job_data.error['message'] | 98 try_job_display_data['error'] = try_job_data.error['message'] |
| 88 # It is possible end_time is not available if the error was timeout. | 99 # It is possible end_time is not available if the error was timeout. |
| 89 try_job_display_data['end_time'] = _FormatDatetime( | 100 try_job_display_data['execution_time'] = _FormatDuration( |
| 90 try_job_data.end_time) | 101 try_job_data.start_time, try_job_data.end_time) |
| 91 try_jobs_with_error.append(try_job_display_data) | 102 try_jobs_with_error.append(try_job_display_data) |
| 92 else: | 103 else: |
| 93 try_job_display_data['culprit_found'] = bool(try_job_data.culprits) | 104 try_job_display_data['culprit_found'] = bool(try_job_data.culprits) |
| 94 try_job_display_data['end_time'] = ( | 105 try_job_display_data['execution_time'] = _FormatDuration( |
| 95 _FormatDatetime(try_job_data.end_time)) | 106 try_job_data.start_time, try_job_data.end_time) |
| 96 successfully_completed_try_jobs.append(try_job_display_data) | 107 successfully_completed_try_jobs.append(try_job_display_data) |
| 97 | 108 |
| 98 data = { | 109 data = { |
| 99 'start_date': _FormatDatetime(start_date), | 110 'start_date': _FormatDatetime(start_date), |
| 100 'end_date': _FormatDatetime(end_date), | 111 'end_date': _FormatDatetime(end_date), |
| 101 'try_jobs_in_progress': try_jobs_in_progress, | 112 'try_jobs_in_progress': try_jobs_in_progress, |
| 102 'try_jobs_with_error': try_jobs_with_error, | 113 'try_jobs_with_error': try_jobs_with_error, |
| 103 'successfully_completed_try_jobs': successfully_completed_try_jobs | 114 'successfully_completed_try_jobs': successfully_completed_try_jobs |
| 104 } | 115 } |
| 105 | 116 |
| 106 return { | 117 return { |
| 107 'template': 'try_job_dashboard.html', | 118 'template': 'try_job_dashboard.html', |
| 108 'data': data | 119 'data': data |
| 109 } | 120 } |
| OLD | NEW |