Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 import time | 5 import time |
| 6 | 6 |
| 7 from common import buildbucket_client | 7 from common import buildbucket_client |
| 8 from common.buildbucket_client import BuildbucketBuild | |
| 8 from model import wf_analysis_status | 9 from model import wf_analysis_status |
| 9 from model.wf_try_job import WfTryJob | 10 from model.wf_try_job import WfTryJob |
| 10 from pipeline_wrapper import BasePipeline | 11 from pipeline_wrapper import BasePipeline |
| 11 from pipeline_wrapper import pipeline | 12 from pipeline_wrapper import pipeline |
| 13 from waterfall.try_job_type import TryJobType | |
| 12 | 14 |
| 13 | 15 |
| 14 class MonitorTryJobPipeline(BasePipeline): | 16 class MonitorTryJobPipeline(BasePipeline): |
| 15 """A pipeline for monitoring a try job and recording results when it's done. | 17 """A pipeline for monitoring a try job and recording results when it's done. |
| 16 | 18 |
| 17 The result will be stored to compile_results or test_results according to | 19 The result will be stored to compile_results or test_results according to |
| 18 which type of build failure we are running try job for. | 20 which type of build failure we are running try job for. |
| 19 """ | 21 """ |
| 20 | 22 |
| 23 def _UpdateTryJobResult( | |
| 24 self, status, master_name, builder_name, build_number, try_job_type, | |
| 25 try_job_id, try_job_url, result_content=None): | |
| 26 """Updates try job result based on responsed try job status and result.""" | |
| 27 result = { | |
| 28 'report': result_content, | |
| 29 'url': try_job_url, | |
| 30 'try_job_id': try_job_id, | |
| 31 } | |
| 32 | |
| 33 try_job_result = WfTryJob.Get(master_name, builder_name, build_number) | |
| 34 if try_job_type == TryJobType.COMPILE: | |
| 35 result_to_update = try_job_result.compile_results | |
| 36 else: | |
| 37 result_to_update = try_job_result.test_results | |
| 38 if (result_to_update and | |
| 39 result_to_update[-1]['try_job_id'] == try_job_id): | |
| 40 result_to_update[-1].update(result) | |
| 41 else: # pragma: no cover | |
| 42 # Normally result for current try job should've been saved in | |
| 43 # schedule_try_job_pipeline, so this branch shouldn't be reached. | |
| 44 result_to_update.append(result) | |
| 45 | |
| 46 if status == BuildbucketBuild.STARTED: # pragma: no cover | |
| 47 try_job_result.status = wf_analysis_status.ANALYZING | |
| 48 try_job_result.put() | |
| 49 return result_to_update | |
| 50 | |
| 21 # Arguments number differs from overridden method - pylint: disable=W0221 | 51 # Arguments number differs from overridden method - pylint: disable=W0221 |
| 22 # TODO(chanli): Handle try job for test failures later. | 52 # TODO(chanli): Handle try job for test failures later. |
| 23 def run(self, master_name, builder_name, build_number, try_job_id): | 53 def run( |
| 54 self, master_name, builder_name, build_number, try_job_type, try_job_id): | |
| 24 assert try_job_id | 55 assert try_job_id |
| 25 | 56 |
| 26 timeout_hours = 5 # Timeout after 5 hours. | 57 timeout_hours = 5 # Timeout after 5 hours. |
|
qyearsley
2016/02/03 18:55:14
This comment is redundant and can be removed.
chanli
2016/02/03 23:44:13
Done.
| |
| 27 deadline = time.time() + timeout_hours * 60 * 60 | 58 deadline = time.time() + timeout_hours * 60 * 60 |
| 28 | 59 |
| 29 already_set_started = False | 60 already_set_started = False |
| 30 while True: | 61 while True: |
| 31 error, build = buildbucket_client.GetTryJobs([try_job_id])[0] | 62 error, build = buildbucket_client.GetTryJobs([try_job_id])[0] |
| 32 if error: # pragma: no cover | 63 if error: # pragma: no cover |
| 33 raise pipeline.Retry( | 64 raise pipeline.Retry( |
| 34 'Error "%s" occurred. Reason: "%s"' % (error.message, error.reason)) | 65 'Error "%s" occurred. Reason: "%s"' % (error.message, error.reason)) |
| 35 elif build.status == 'COMPLETED': | 66 elif build.status == BuildbucketBuild.COMPLETED: |
| 36 result = { | 67 result_to_update = self._UpdateTryJobResult( |
| 37 'report': build.report, | 68 BuildbucketBuild.COMPLETED, master_name, builder_name, build_number, |
| 38 'url': build.url, | 69 try_job_type, try_job_id, build.url, build.report) |
| 39 'try_job_id': try_job_id, | 70 return result_to_update[-1] |
| 40 } | |
| 41 | 71 |
| 42 try_job_result = WfTryJob.Get(master_name, builder_name, build_number) | |
| 43 if (try_job_result.compile_results and | |
| 44 try_job_result.compile_results[-1]['try_job_id'] == try_job_id): | |
| 45 try_job_result.compile_results[-1].update(result) | |
| 46 else: # pragma: no cover | |
| 47 try_job_result.compile_results.append(result) | |
| 48 | |
| 49 try_job_result.put() | |
| 50 return try_job_result.compile_results[-1] | |
| 51 else: # pragma: no cover | 72 else: # pragma: no cover |
| 52 if build.status == 'STARTED' and not already_set_started: | 73 if build.status == BuildbucketBuild.STARTED and not already_set_started: |
| 53 result = { | 74 self._UpdateTryJobResult( |
| 54 'report': None, | 75 BuildbucketBuild.STARTED, master_name, builder_name, build_number, |
| 55 'url': build.url, | 76 try_job_type, try_job_id, build.url) |
| 56 'try_job_id': try_job_id, | |
| 57 } | |
| 58 | |
| 59 try_job_result = WfTryJob.Get(master_name, builder_name, build_number) | |
| 60 if (try_job_result.compile_results and | |
| 61 try_job_result.compile_results[-1]['try_job_id'] == try_job_id): | |
| 62 try_job_result.compile_results[-1].update(result) | |
| 63 else: # pragma: no cover | |
| 64 # Normally result for current try job should've been saved in | |
| 65 # schedule_try_job_pipeline, so this branch shouldn't be reached. | |
| 66 try_job_result.compile_results.append(result) | |
| 67 | |
| 68 try_job_result.status = wf_analysis_status.ANALYZING | |
| 69 try_job_result.put() | |
| 70 already_set_started = True | 77 already_set_started = True |
| 71 | 78 |
| 72 time.sleep(60) | 79 time.sleep(60) |
| 73 | 80 |
| 74 if time.time() > deadline: # pragma: no cover | 81 if time.time() > deadline: # pragma: no cover |
| 82 try_job_result = WfTryJob.Get(master_name, builder_name, build_number) | |
| 75 try_job_result.status = wf_analysis_status.ERROR | 83 try_job_result.status = wf_analysis_status.ERROR |
| 76 try_job_result.put() | 84 try_job_result.put() |
| 77 # Explicitly abort the whole pipeline. | 85 # Explicitly abort the whole pipeline. |
| 78 raise pipeline.Abort( | 86 raise pipeline.Abort( |
| 79 'Try job %s timed out after %d hours.' % ( | 87 'Try job %s timed out after %d hours.' % ( |
| 80 try_job_id, timeout_hours)) | 88 try_job_id, timeout_hours)) |
| OLD | NEW |