| 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 fbee936bb1f2f8025e69366dc90b5329998177a3..fe121fcd30fa3883fb64b46aeab87dfcecd736c2 100644 | 
| --- a/appengine/findit/waterfall/monitor_try_job_pipeline.py | 
| +++ b/appengine/findit/waterfall/monitor_try_job_pipeline.py | 
| @@ -5,10 +5,12 @@ | 
| import time | 
|  | 
| from common import buildbucket_client | 
| +from common.buildbucket_client import BuildbucketBuild | 
| 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 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 = { | 
| +        'report': 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.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 == BuildbucketBuild.STARTED:  # pragma: no cover | 
| +      try_job_result.status = wf_analysis_status.ANALYZING | 
| +    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 = { | 
| -            'report': build.report, | 
| -            '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 == BuildbucketBuild.COMPLETED: | 
| +        result_to_update = self._UpdateTryJobResult( | 
| +            BuildbucketBuild.COMPLETED, master_name, builder_name, build_number, | 
| +            try_job_type, try_job_id, build.url, build.report) | 
| +        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 = { | 
| -              'report': 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 == BuildbucketBuild.STARTED and not already_set_started: | 
| +          self._UpdateTryJobResult( | 
| +              BuildbucketBuild.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. | 
|  |