Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: appengine/findit/waterfall/monitor_try_job_pipeline.py

Issue 1591003002: [Findit] Modify tryjob pipelines to trigger try jobs for test failure. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 from pipeline_wrapper import pipeline 11 from pipeline_wrapper import pipeline
12 12
13 13
14 class MonitorTryJobPipeline(BasePipeline): 14 class MonitorTryJobPipeline(BasePipeline):
15 """A pipeline for monitoring a tryjob and recording results when it's done. 15 """A pipeline for monitoring a tryjob and recording results when it's done.
16 16
17 The result will be stored to compile_results or test_results according to 17 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. 18 which type of build failure we are running try job for.
19 """ 19 """
20 20
21 # Arguments number differs from overridden method - pylint: disable=W0221 21 # Arguments number differs from overridden method - pylint: disable=W0221
22 # TODO(chanli): Handle try job for test failures later. 22 # TODO(chanli): Handle try job for test failures later.
23 def run(self, master_name, builder_name, build_number, try_job_id): 23 def run(
24 self, master_name, builder_name, build_number, try_job_type, try_job_id):
24 assert try_job_id 25 assert try_job_id
25 26
26 timeout_hours = 5 # Timeout after 5 hours. 27 timeout_hours = 5 # Timeout after 5 hours.
27 deadline = time.time() + timeout_hours * 60 * 60 28 deadline = time.time() + timeout_hours * 60 * 60
28 29
29 already_set_started = False 30 already_set_started = False
30 while True: 31 while True:
31 error, build = buildbucket_client.GetTryJobs([try_job_id])[0] 32 error, build = buildbucket_client.GetTryJobs([try_job_id])[0]
32 if error: # pragma: no cover 33 if error: # pragma: no cover
33 raise pipeline.Retry( 34 raise pipeline.Retry(
34 'Error "%s" occurred. Reason: "%s"' % (error.message, error.reason)) 35 'Error "%s" occurred. Reason: "%s"' % (error.message, error.reason))
35 elif build.status == 'COMPLETED': 36 elif build.status == 'COMPLETED':
36 result = { 37 result = {
37 'result': build.result, 38 'result': build.result,
38 'url': build.url, 39 'url': build.url,
39 'try_job_id': try_job_id, 40 'try_job_id': try_job_id,
40 } 41 }
41 42
42 try_job_result = WfTryJob.Get(master_name, builder_name, build_number) 43 try_job_result = WfTryJob.Get(master_name, builder_name, build_number)
43 if (try_job_result.compile_results and 44 if try_job_type == 'compile':
44 try_job_result.compile_results[-1]['try_job_id'] == try_job_id): 45 if (try_job_result.compile_results and
45 try_job_result.compile_results[-1].update(result) 46 try_job_result.compile_results[-1]['try_job_id'] == try_job_id):
46 else: # pragma: no cover 47 try_job_result.compile_results[-1].update(result)
47 try_job_result.compile_results.append(result) 48 else: # pragma: no cover
49 try_job_result.compile_results.append(result)
50 try_job_result.put()
51 return try_job_result.compile_results[-1]
52 else: # Test failures.
53 if (try_job_result.test_results and
54 try_job_result.test_results[-1]['try_job_id'] == try_job_id):
55 try_job_result.test_results[-1].update(result)
56 else: # pragma: no cover
57 try_job_result.test_results.append(result)
58 try_job_result.put()
59 return try_job_result.test_results[-1]
48 60
49 try_job_result.put()
50 return try_job_result.compile_results[-1]
51 else: # pragma: no cover 61 else: # pragma: no cover
52 if build.status == 'STARTED' and not already_set_started: 62 if build.status == 'STARTED' and not already_set_started:
53 result = { 63 result = {
54 'result': None, 64 'result': None,
55 'url': build.url, 65 'url': build.url,
56 'try_job_id': try_job_id, 66 'try_job_id': try_job_id,
57 } 67 }
58 68
59 try_job_result = WfTryJob.Get(master_name, builder_name, build_number) 69 try_job_result = WfTryJob.Get(master_name, builder_name, build_number)
60 if (try_job_result.compile_results and 70 if try_job_type == 'compile':
61 try_job_result.compile_results[-1]['try_job_id'] == try_job_id): 71 if (try_job_result.compile_results and
62 try_job_result.compile_results[-1].update(result) 72 try_job_result.compile_results[-1]['try_job_id'] == try_job_id):
63 else: # pragma: no cover 73 try_job_result.compile_results[-1].update(result)
64 # Normally result for current try job should've been saved in 74 else: # pragma: no cover
65 # schedule_try_job_pipeline, so this branch shouldn't be reached. 75 # Normally result for current try job should've been saved in
66 try_job_result.compile_results.append(result) 76 # schedule_try_job_pipeline, so this branch shouldn't be reached.
77 try_job_result.compile_results.append(result)
78 else:
79 if (try_job_result.test_results and
80 try_job_result.test_results[-1]['try_job_id'] == try_job_id):
81 try_job_result.test_results[-1].update(result)
82 else: # pragma: no cover
83 # Normally result for current try job should've been saved in
84 # schedule_try_job_pipeline, so this branch shouldn't be reached.
85 try_job_result.test_results.append(result)
67 86
68 try_job_result.status = wf_analysis_status.ANALYZING 87 try_job_result.status = wf_analysis_status.ANALYZING
69 try_job_result.put() 88 try_job_result.put()
70 already_set_started = True 89 already_set_started = True
71 90
72 time.sleep(60) 91 time.sleep(60)
73 92
74 if time.time() > deadline: # pragma: no cover 93 if time.time() > deadline: # pragma: no cover
75 try_job_result.status = wf_analysis_status.ERROR 94 try_job_result.status = wf_analysis_status.ERROR
76 try_job_result.put() 95 try_job_result.put()
77 # Explicitly abort the whole pipeline. 96 # Explicitly abort the whole pipeline.
78 raise pipeline.Abort( 97 raise pipeline.Abort(
79 'Try job %s timed out after %d hours.' % ( 98 'Try job %s timed out after %d hours.' % (
80 try_job_id, timeout_hours)) 99 try_job_id, timeout_hours))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698