Chromium Code Reviews| Index: appengine/findit/waterfall/monitor_try_job_pipeline.py |
| diff --git a/appengine/findit/waterfall/monitor_try_job_pipeline.py b/appengine/findit/waterfall/monitor_try_job_pipeline.py |
| index 92acfe2e7a02fd6b9e5d59f5a1d5b402041910da..c283a1584c561e69a2dba77a06972bcdf540c4fb 100644 |
| --- a/appengine/findit/waterfall/monitor_try_job_pipeline.py |
| +++ b/appengine/findit/waterfall/monitor_try_job_pipeline.py |
| @@ -9,6 +9,8 @@ from model import wf_analysis_status |
| from model.wf_try_job import WfTryJob |
| from pipeline_wrapper import BasePipeline |
| from pipeline_wrapper import pipeline |
| +from waterfall.try_job_enums import TryJobStatus |
| +from waterfall.try_job_enums import TryJobType |
| class MonitorTryJobPipeline(BasePipeline): |
| @@ -18,9 +20,38 @@ class MonitorTryJobPipeline(BasePipeline): |
| which type of build failure we are running try job for. |
| """ |
| + def _UpdateTryJobResult( |
| + self, status, master_name, builder_name, build_number, try_job_type, |
| + try_job_id, try_job_url, result_content=None): |
| + """Updates try job result based on responsed try job status and result.""" |
| + result = { |
| + 'result': result_content, |
| + 'url': try_job_url, |
| + 'try_job_id': try_job_id, |
| + } |
| + |
| + try_job_result = WfTryJob.Get(master_name, builder_name, build_number) |
| + if try_job_type == TryJobType.type_compile: |
| + result_to_update = try_job_result.compile_results |
| + else: |
| + result_to_update = try_job_result.test_results |
| + if (result_to_update and |
| + result_to_update[-1]['try_job_id'] == try_job_id): |
| + result_to_update[-1].update(result) |
| + else: # pragma: no cover |
| + # Normally result for current try job should've been saved in |
| + # schedule_try_job_pipeline, so this branch shouldn't be reached. |
| + result_to_update.append(result) |
| + |
| + if status == TryJobStatus.started: # pragma: no cover |
| + try_job_result.status = wf_analysis_status.ANALYZING |
|
stgao
2016/01/28 19:33:51
What if status == 'COMPLETED'?
chanli
2016/01/28 22:40:12
I will change the try_job_result.status to ANALYZE
|
| + try_job_result.put() |
| + return result_to_update |
| + |
| # Arguments number differs from overridden method - pylint: disable=W0221 |
| # TODO(chanli): Handle try job for test failures later. |
| - def run(self, master_name, builder_name, build_number, try_job_id): |
| + def run( |
| + self, master_name, builder_name, build_number, try_job_type, try_job_id): |
| assert try_job_id |
| timeout_hours = 5 # Timeout after 5 hours. |
| @@ -32,46 +63,23 @@ class MonitorTryJobPipeline(BasePipeline): |
| if error: # pragma: no cover |
| raise pipeline.Retry( |
| 'Error "%s" occurred. Reason: "%s"' % (error.message, error.reason)) |
| - elif build.status == 'COMPLETED': |
| - result = { |
| - 'result': build.result, |
| - 'url': build.url, |
| - 'try_job_id': try_job_id, |
| - } |
| - |
| - try_job_result = WfTryJob.Get(master_name, builder_name, build_number) |
| - if (try_job_result.compile_results and |
| - try_job_result.compile_results[-1]['try_job_id'] == try_job_id): |
| - try_job_result.compile_results[-1].update(result) |
| - else: # pragma: no cover |
| - try_job_result.compile_results.append(result) |
| + elif build.status == TryJobStatus.completed: |
|
stgao
2016/01/28 19:33:52
Isn't the enum available in common.buildbucket_cli
chanli
2016/01/28 22:40:12
Done.
|
| + result_to_update = self._UpdateTryJobResult( |
| + TryJobStatus.completed, master_name, builder_name, build_number, |
| + try_job_type, try_job_id, build.url, build.result) |
| + return result_to_update[-1] |
| - try_job_result.put() |
| - return try_job_result.compile_results[-1] |
| else: # pragma: no cover |
| - if build.status == 'STARTED' and not already_set_started: |
| - result = { |
| - 'result': None, |
| - 'url': build.url, |
| - 'try_job_id': try_job_id, |
| - } |
| - |
| - try_job_result = WfTryJob.Get(master_name, builder_name, build_number) |
| - if (try_job_result.compile_results and |
| - try_job_result.compile_results[-1]['try_job_id'] == try_job_id): |
| - try_job_result.compile_results[-1].update(result) |
| - else: # pragma: no cover |
| - # Normally result for current try job should've been saved in |
| - # schedule_try_job_pipeline, so this branch shouldn't be reached. |
| - try_job_result.compile_results.append(result) |
| - |
| - try_job_result.status = wf_analysis_status.ANALYZING |
| - try_job_result.put() |
| + if build.status == TryJobStatus.started and not already_set_started: |
| + self._UpdateTryJobResult( |
| + TryJobStatus.started, master_name, builder_name, build_number, |
| + try_job_type, try_job_id, build.url) |
| already_set_started = True |
| time.sleep(60) |
| if time.time() > deadline: # pragma: no cover |
| + try_job_result = WfTryJob.Get(master_name, builder_name, build_number) |
| try_job_result.status = wf_analysis_status.ERROR |
| try_job_result.put() |
| # Explicitly abort the whole pipeline. |