| 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 model import wf_analysis_status | 8 from model import wf_analysis_status |
| 9 from model.wf_try_job import WfTryJob | 9 from model.wf_try_job import WfTryJob |
| 10 from pipeline_wrapper import BasePipeline | 10 from pipeline_wrapper import BasePipeline |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 deadline = time.time() + timeout_hours * 60 * 60 | 27 deadline = time.time() + timeout_hours * 60 * 60 |
| 28 | 28 |
| 29 already_set_started = False | 29 already_set_started = False |
| 30 while True: | 30 while True: |
| 31 error, build = buildbucket_client.GetTryJobs([try_job_id])[0] | 31 error, build = buildbucket_client.GetTryJobs([try_job_id])[0] |
| 32 if error: # pragma: no cover | 32 if error: # pragma: no cover |
| 33 raise pipeline.Retry( | 33 raise pipeline.Retry( |
| 34 'Error "%s" occurred. Reason: "%s"' % (error.message, error.reason)) | 34 'Error "%s" occurred. Reason: "%s"' % (error.message, error.reason)) |
| 35 elif build.status == 'COMPLETED': | 35 elif build.status == 'COMPLETED': |
| 36 result = { | 36 result = { |
| 37 'result': build.result, | 37 'report': build.report, |
| 38 'url': build.url, | 38 'url': build.url, |
| 39 'try_job_id': try_job_id, | 39 'try_job_id': try_job_id, |
| 40 } | 40 } |
| 41 | 41 |
| 42 try_job_result = WfTryJob.Get(master_name, builder_name, build_number) | 42 try_job_result = WfTryJob.Get(master_name, builder_name, build_number) |
| 43 if (try_job_result.compile_results and | 43 if (try_job_result.compile_results and |
| 44 try_job_result.compile_results[-1]['try_job_id'] == try_job_id): | 44 try_job_result.compile_results[-1]['try_job_id'] == try_job_id): |
| 45 try_job_result.compile_results[-1].update(result) | 45 try_job_result.compile_results[-1].update(result) |
| 46 else: # pragma: no cover | 46 else: # pragma: no cover |
| 47 try_job_result.compile_results.append(result) | 47 try_job_result.compile_results.append(result) |
| 48 | 48 |
| 49 try_job_result.put() | 49 try_job_result.put() |
| 50 return try_job_result.compile_results[-1] | 50 return try_job_result.compile_results[-1] |
| 51 else: # pragma: no cover | 51 else: # pragma: no cover |
| 52 if build.status == 'STARTED' and not already_set_started: | 52 if build.status == 'STARTED' and not already_set_started: |
| 53 result = { | 53 result = { |
| 54 'result': None, | 54 'report': None, |
| 55 'url': build.url, | 55 'url': build.url, |
| 56 'try_job_id': try_job_id, | 56 'try_job_id': try_job_id, |
| 57 } | 57 } |
| 58 | 58 |
| 59 try_job_result = WfTryJob.Get(master_name, builder_name, build_number) | 59 try_job_result = WfTryJob.Get(master_name, builder_name, build_number) |
| 60 if (try_job_result.compile_results and | 60 if (try_job_result.compile_results and |
| 61 try_job_result.compile_results[-1]['try_job_id'] == try_job_id): | 61 try_job_result.compile_results[-1]['try_job_id'] == try_job_id): |
| 62 try_job_result.compile_results[-1].update(result) | 62 try_job_result.compile_results[-1].update(result) |
| 63 else: # pragma: no cover | 63 else: # pragma: no cover |
| 64 # Normally result for current try job should've been saved in | 64 # Normally result for current try job should've been saved in |
| 65 # schedule_try_job_pipeline, so this branch shouldn't be reached. | 65 # schedule_try_job_pipeline, so this branch shouldn't be reached. |
| 66 try_job_result.compile_results.append(result) | 66 try_job_result.compile_results.append(result) |
| 67 | 67 |
| 68 try_job_result.status = wf_analysis_status.ANALYZING | 68 try_job_result.status = wf_analysis_status.ANALYZING |
| 69 try_job_result.put() | 69 try_job_result.put() |
| 70 already_set_started = True | 70 already_set_started = True |
| 71 | 71 |
| 72 time.sleep(60) | 72 time.sleep(60) |
| 73 | 73 |
| 74 if time.time() > deadline: # pragma: no cover | 74 if time.time() > deadline: # pragma: no cover |
| 75 try_job_result.status = wf_analysis_status.ERROR | 75 try_job_result.status = wf_analysis_status.ERROR |
| 76 try_job_result.put() | 76 try_job_result.put() |
| 77 # Explicitly abort the whole pipeline. | 77 # Explicitly abort the whole pipeline. |
| 78 raise pipeline.Abort( | 78 raise pipeline.Abort( |
| 79 'Try job %s timed out after %d hours.' % ( | 79 'Try job %s timed out after %d hours.' % ( |
| 80 try_job_id, timeout_hours)) | 80 try_job_id, timeout_hours)) |
| OLD | NEW |