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

Side by Side Diff: appengine/findit/crash/crash_pipeline.py

Issue 2480593002: [Predator] Move time_util from common/ to lib/, split code review related part to code_review_util (Closed)
Patch Set: Created 4 years, 1 month 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 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 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 copy 5 import copy
6 import json 6 import json
7 import logging 7 import logging
8 8
9 from common import appengine_util 9 from common import appengine_util
10 from common import pubsub_util 10 from common import pubsub_util
11 from common import time_util
12 from common.http_client_appengine import HttpClientAppengine 11 from common.http_client_appengine import HttpClientAppengine
13 from common.pipeline_wrapper import BasePipeline 12 from common.pipeline_wrapper import BasePipeline
14 from common.pipeline_wrapper import pipeline 13 from common.pipeline_wrapper import pipeline
15 from crash import findit_for_chromecrash 14 from crash import findit_for_chromecrash
16 from crash import findit_for_clusterfuzz 15 from crash import findit_for_clusterfuzz
17 from crash.type_enums import CrashClient 16 from crash.type_enums import CrashClient
17 from lib import time_util
18 from lib.gitiles import gitiles_repository 18 from lib.gitiles import gitiles_repository
19 from model import analysis_status 19 from model import analysis_status
20 20
21 21
22 # TODO(http://crbug.com/659346): write complete coverage tests for this. 22 # TODO(http://crbug.com/659346): write complete coverage tests for this.
23 def FinditForClientID(client_id): # pragma: no cover 23 def FinditForClientID(client_id): # pragma: no cover
24 """Construct a Findit object from a client id string specifying the class. 24 """Construct a Findit object from a client id string specifying the class.
25 25
26 We cannot pass Findit objects to the various methods in 26 We cannot pass Findit objects to the various methods in
27 ``crash.crash_pipeline``, because they are not JSON serializable. For 27 ``crash.crash_pipeline``, because they are not JSON serializable. For
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 # ``was_aborted`` can't be altered directly. 100 # ``was_aborted`` can't be altered directly.
101 def _PutAbortedError(self): 101 def _PutAbortedError(self):
102 """Update the ndb.Model to indicate that this pipeline was aborted.""" 102 """Update the ndb.Model to indicate that this pipeline was aborted."""
103 logging.error('Aborted analysis for %s', repr(self._crash_identifiers)) 103 logging.error('Aborted analysis for %s', repr(self._crash_identifiers))
104 analysis = self._findit.GetAnalysis(self._crash_identifiers) 104 analysis = self._findit.GetAnalysis(self._crash_identifiers)
105 analysis.status = analysis_status.ERROR 105 analysis.status = analysis_status.ERROR
106 analysis.put() 106 analysis.put()
107 107
108 # TODO(http://crbug.com/659346): we misplaced the coverage test; find it! 108 # TODO(http://crbug.com/659346): we misplaced the coverage test; find it!
109 # Arguments number differs from overridden method - pylint: disable=W0221 109 # Arguments number differs from overridden method - pylint: disable=W0221
110 def run(self): 110 def run(self, *_args, **_kargs):
wrengr 2016/11/03 22:17:58 Hrm, this should've been fixed in the landed versi
Sharu Jiang 2016/11/04 01:02:34 Done.
111 # TODO(wrengr): shouldn't this method somehow call _NeedsNewAnalysis 111 # TODO(wrengr): shouldn't this method somehow call _NeedsNewAnalysis
112 # to guard against race conditions? 112 # to guard against race conditions?
113 analysis = self._findit.GetAnalysis(self._crash_identifiers) 113 analysis = self._findit.GetAnalysis(self._crash_identifiers)
114 114
115 # Update the model's status to say we're in the process of doing analysis. 115 # Update the model's status to say we're in the process of doing analysis.
116 analysis.pipeline_status_path = self.pipeline_status_path() 116 analysis.pipeline_status_path = self.pipeline_status_path()
117 analysis.status = analysis_status.RUNNING 117 analysis.status = analysis_status.RUNNING
118 analysis.started_time = time_util.GetUTCNow() 118 analysis.started_time = time_util.GetUTCNow()
119 analysis.findit_version = appengine_util.GetCurrentVersion() 119 analysis.findit_version = appengine_util.GetCurrentVersion()
120 analysis.put() 120 analysis.put()
(...skipping 24 matching lines...) Expand all
145 145
146 146
147 class PublishResultPipeline(CrashBasePipeline): 147 class PublishResultPipeline(CrashBasePipeline):
148 # TODO(http://crbug.com/659346): we misplaced the coverage test; find it! 148 # TODO(http://crbug.com/659346): we misplaced the coverage test; find it!
149 def finalized(self): 149 def finalized(self):
150 if self.was_aborted: # pragma: no cover. 150 if self.was_aborted: # pragma: no cover.
151 logging.error('Failed to publish %s analysis result for %s', 151 logging.error('Failed to publish %s analysis result for %s',
152 repr(self._crash_identifiers), self.client_id) 152 repr(self._crash_identifiers), self.client_id)
153 153
154 # Arguments number differs from overridden method - pylint: disable=W0221 154 # Arguments number differs from overridden method - pylint: disable=W0221
155 def run(self): 155 def run(self, *_args, **_kargs):
wrengr 2016/11/03 22:17:58 ditto
Sharu Jiang 2016/11/04 01:02:34 Done.
156 analysis = self._findit.GetAnalysis(self._crash_identifiers) 156 analysis = self._findit.GetAnalysis(self._crash_identifiers)
157 result = analysis.ToPublishableResult(self._crash_identifiers) 157 result = analysis.ToPublishableResult(self._crash_identifiers)
158 messages_data = [json.dumps(result, sort_keys=True)] 158 messages_data = [json.dumps(result, sort_keys=True)]
159 159
160 # TODO(http://crbug.com/659354): remove Findit's dependency on CrashConfig. 160 # TODO(http://crbug.com/659354): remove Findit's dependency on CrashConfig.
161 client_config = self._findit.config 161 client_config = self._findit.config
162 # TODO(katesonia): Clean string uses in config. 162 # TODO(katesonia): Clean string uses in config.
163 topic = client_config['analysis_result_pubsub_topic'] 163 topic = client_config['analysis_result_pubsub_topic']
164 pubsub_util.PublishMessagesToTopic(messages_data, topic) 164 pubsub_util.PublishMessagesToTopic(messages_data, topic)
165 logging.info('Published %s analysis result for %s', self.client_id, 165 logging.info('Published %s analysis result for %s', self.client_id,
(...skipping 12 matching lines...) Expand all
178 because the ``run`` and ``finalized`` methods are executed in different 178 because the ``run`` and ``finalized`` methods are executed in different
179 processes. 179 processes.
180 """ 180 """
181 def __init__(self, client_id, crash_identifiers): 181 def __init__(self, client_id, crash_identifiers):
182 super(CrashWrapperPipeline, self).__init__(client_id, crash_identifiers) 182 super(CrashWrapperPipeline, self).__init__(client_id, crash_identifiers)
183 self._crash_identifiers = crash_identifiers 183 self._crash_identifiers = crash_identifiers
184 self._client_id = client_id 184 self._client_id = client_id
185 185
186 # TODO(http://crbug.com/659346): write coverage tests. 186 # TODO(http://crbug.com/659346): write coverage tests.
187 # Arguments number differs from overridden method - pylint: disable=W0221 187 # Arguments number differs from overridden method - pylint: disable=W0221
188 def run(self): # pragma: no cover 188 def run(self, *_args, **_kargs): # pragma: no cover
wrengr 2016/11/03 22:17:58 ditto
Sharu Jiang 2016/11/04 01:02:34 Done.
189 run_analysis = yield CrashAnalysisPipeline( 189 run_analysis = yield CrashAnalysisPipeline(
190 self._client_id, self._crash_identifiers) 190 self._client_id, self._crash_identifiers)
191 with pipeline.After(run_analysis): 191 with pipeline.After(run_analysis):
192 yield PublishResultPipeline(self._client_id, self._crash_identifiers) 192 yield PublishResultPipeline(self._client_id, self._crash_identifiers)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698