| 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 | 4 |
| 5 from collections import defaultdict | 5 from collections import defaultdict |
| 6 import datetime | 6 import datetime |
| 7 import logging | 7 import logging |
| 8 import time | 8 import time |
| 9 | 9 |
| 10 from common.http_client_appengine import HttpClientAppengine as HttpClient | 10 from common.http_client_appengine import HttpClientAppengine as HttpClient |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 task_started = False | 79 task_started = False |
| 80 task_completed = False | 80 task_completed = False |
| 81 tests_statuses = {} | 81 tests_statuses = {} |
| 82 step_name_no_platform = None | 82 step_name_no_platform = None |
| 83 | 83 |
| 84 while not task_completed: | 84 while not task_completed: |
| 85 # Keeps monitoring the swarming task, waits for it to complete. | 85 # Keeps monitoring the swarming task, waits for it to complete. |
| 86 data = swarming_util.GetSwarmingTaskResultById( | 86 data = swarming_util.GetSwarmingTaskResultById( |
| 87 task_id, self.HTTP_CLIENT) | 87 task_id, self.HTTP_CLIENT) |
| 88 task_state = data['state'] | 88 task_state = data['state'] |
| 89 exit_code = (data['exit_code'] if |
| 90 task_state == swarming_util.STATE_COMPLETED else None) |
| 89 step_name_no_platform = swarming_util.GetTagValue( | 91 step_name_no_platform = swarming_util.GetTagValue( |
| 90 data.get('tags', {}), 'ref_name') | 92 data.get('tags', {}), 'ref_name') |
| 91 if task_state not in swarming_util.STATES_RUNNING: | 93 if task_state not in swarming_util.STATES_RUNNING: |
| 92 task_completed = True | 94 task_completed = True |
| 93 task = self._GetSwarmingTask(*call_args) | 95 task = self._GetSwarmingTask(*call_args) |
| 94 if task_state == swarming_util.STATE_COMPLETED: | 96 if (task_state == swarming_util.STATE_COMPLETED and |
| 97 int(exit_code) != swarming_util.TASK_FAILED): |
| 95 outputs_ref = data.get('outputs_ref') | 98 outputs_ref = data.get('outputs_ref') |
| 96 output_json = swarming_util.GetSwarmingTaskFailureLog( | 99 output_json = swarming_util.GetSwarmingTaskFailureLog( |
| 97 outputs_ref, self.HTTP_CLIENT) | 100 outputs_ref, self.HTTP_CLIENT) |
| 98 tests_statuses = self._CheckTestsRunStatuses( | 101 tests_statuses = self._CheckTestsRunStatuses( |
| 99 output_json, *call_args) | 102 output_json, *call_args) |
| 100 task.status = analysis_status.COMPLETED | 103 task.status = analysis_status.COMPLETED |
| 101 task.tests_statuses = tests_statuses | 104 task.tests_statuses = tests_statuses |
| 102 else: | 105 else: |
| 103 task.status = analysis_status.ERROR | 106 task.status = analysis_status.ERROR |
| 104 logging.error('Swarming task stopped with status: %s' % ( | 107 logging_str = 'Swarming task stopped with status: %s' % task_state |
| 105 task_state)) | 108 if exit_code: |
| 109 logging_str += ' and exit_code: %s - %s' % ( |
| 110 exit_code, swarming_util.EXIT_CODE_DESCRIPTIONS[int(exit_code)]) |
| 111 logging.error(logging_str) |
| 112 |
| 106 priority_str = swarming_util.GetTagValue( | 113 priority_str = swarming_util.GetTagValue( |
| 107 data.get('tags', {}), 'priority') | 114 data.get('tags', {}), 'priority') |
| 108 if priority_str: | 115 if priority_str: |
| 109 task.parameters['priority'] = int(priority_str) | 116 task.parameters['priority'] = int(priority_str) |
| 110 task.put() | 117 task.put() |
| 111 else: # pragma: no cover | 118 else: # pragma: no cover |
| 112 if task_state == 'RUNNING' and not task_started: | 119 if task_state == 'RUNNING' and not task_started: |
| 113 # swarming task just starts, update status. | 120 # swarming task just starts, update status. |
| 114 task_started = True | 121 task_started = True |
| 115 task = self._GetSwarmingTask(*call_args) | 122 task = self._GetSwarmingTask(*call_args) |
| 116 task.status = analysis_status.RUNNING | 123 task.status = analysis_status.RUNNING |
| 117 task.put() | 124 task.put() |
| 118 time.sleep(server_query_interval_seconds) | 125 time.sleep(server_query_interval_seconds) |
| 119 if time.time() > deadline: | 126 if time.time() > deadline: |
| 120 # Updates status as ERROR. | 127 # Updates status as ERROR. |
| 121 task = self._GetSwarmingTask(*call_args) | 128 task = self._GetSwarmingTask(*call_args) |
| 122 task.status = analysis_status.ERROR | 129 task.status = analysis_status.ERROR |
| 123 task.put() | 130 task.put() |
| 124 logging.error('Swarming task timed out after %d hours.' % timeout_hours) | 131 logging.error('Swarming task timed out after %d hours.' % timeout_hours) |
| 125 break # Stops the loop and return. | 132 break # Stops the loop and return. |
| 126 # Update swarming task metadate. | 133 # Update swarming task metadate. |
| 127 task = self._GetSwarmingTask(*call_args) | 134 task = self._GetSwarmingTask(*call_args) |
| 128 task.created_time = self._ConvertDateTime(data.get('created_ts')) | 135 task.created_time = self._ConvertDateTime(data.get('created_ts')) |
| 129 task.started_time = self._ConvertDateTime(data.get('started_ts')) | 136 task.started_time = self._ConvertDateTime(data.get('started_ts')) |
| 130 task.completed_time = self._ConvertDateTime(data.get('completed_ts')) | 137 task.completed_time = self._ConvertDateTime(data.get('completed_ts')) |
| 131 task.put() | 138 task.put() |
| 132 | 139 |
| 133 return step_name, step_name_no_platform | 140 return step_name, step_name_no_platform |
| OLD | NEW |