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 | 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 = (None if task_state != swarming_util.STATE_COMPLETED | |
| 90 else data['exit_code']) | |
|
lijeffrey
2016/09/07 20:41:38
how about the opposite for readability?
exit_code
chanli
2016/09/07 22:37:11
Done.
| |
| 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 int(exit_code) < 2: |
|
lijeffrey
2016/09/07 20:41:38
why 2? Is there something special about anything <
chanli
2016/09/07 22:37:11
exit_code == 0 means all tests passed; exit_code =
| |
| 95 outputs_ref = data.get('outputs_ref') | 97 outputs_ref = data.get('outputs_ref') |
| 96 output_json = swarming_util.GetSwarmingTaskFailureLog( | 98 output_json = swarming_util.GetSwarmingTaskFailureLog( |
| 97 outputs_ref, self.HTTP_CLIENT) | 99 outputs_ref, self.HTTP_CLIENT) |
| 98 tests_statuses = self._CheckTestsRunStatuses( | 100 tests_statuses = self._CheckTestsRunStatuses( |
| 99 output_json, *call_args) | 101 output_json, *call_args) |
| 100 task.status = analysis_status.COMPLETED | 102 task.status = analysis_status.COMPLETED |
| 101 task.tests_statuses = tests_statuses | 103 task.tests_statuses = tests_statuses |
| 102 else: | 104 else: |
| 103 task.status = analysis_status.ERROR | 105 task.status = analysis_status.ERROR |
| 104 logging.error('Swarming task stopped with status: %s' % ( | 106 logging.error('Swarming task stopped with status: %s and' |
| 105 task_state)) | 107 ' exit_code: %s' % (task_state, exit_code)) |
| 106 priority_str = swarming_util.GetTagValue( | 108 priority_str = swarming_util.GetTagValue( |
| 107 data.get('tags', {}), 'priority') | 109 data.get('tags', {}), 'priority') |
| 108 if priority_str: | 110 if priority_str: |
| 109 task.parameters['priority'] = int(priority_str) | 111 task.parameters['priority'] = int(priority_str) |
| 110 task.put() | 112 task.put() |
| 111 else: # pragma: no cover | 113 else: # pragma: no cover |
| 112 if task_state == 'RUNNING' and not task_started: | 114 if task_state == 'RUNNING' and not task_started: |
| 113 # swarming task just starts, update status. | 115 # swarming task just starts, update status. |
| 114 task_started = True | 116 task_started = True |
| 115 task = self._GetSwarmingTask(*call_args) | 117 task = self._GetSwarmingTask(*call_args) |
| 116 task.status = analysis_status.RUNNING | 118 task.status = analysis_status.RUNNING |
| 117 task.put() | 119 task.put() |
| 118 time.sleep(server_query_interval_seconds) | 120 time.sleep(server_query_interval_seconds) |
| 119 if time.time() > deadline: | 121 if time.time() > deadline: |
| 120 # Updates status as ERROR. | 122 # Updates status as ERROR. |
| 121 task = self._GetSwarmingTask(*call_args) | 123 task = self._GetSwarmingTask(*call_args) |
| 122 task.status = analysis_status.ERROR | 124 task.status = analysis_status.ERROR |
| 123 task.put() | 125 task.put() |
| 124 logging.error('Swarming task timed out after %d hours.' % timeout_hours) | 126 logging.error('Swarming task timed out after %d hours.' % timeout_hours) |
| 125 break # Stops the loop and return. | 127 break # Stops the loop and return. |
| 126 # Update swarming task metadate. | 128 # Update swarming task metadate. |
| 127 task = self._GetSwarmingTask(*call_args) | 129 task = self._GetSwarmingTask(*call_args) |
| 128 task.created_time = self._ConvertDateTime(data.get('created_ts')) | 130 task.created_time = self._ConvertDateTime(data.get('created_ts')) |
| 129 task.started_time = self._ConvertDateTime(data.get('started_ts')) | 131 task.started_time = self._ConvertDateTime(data.get('started_ts')) |
| 130 task.completed_time = self._ConvertDateTime(data.get('completed_ts')) | 132 task.completed_time = self._ConvertDateTime(data.get('completed_ts')) |
| 131 task.put() | 133 task.put() |
| 132 | 134 |
| 133 return step_name, step_name_no_platform | 135 return step_name, step_name_no_platform |
| OLD | NEW |