OLD | NEW |
---|---|
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 logging | 5 import logging |
6 import time | 6 import time |
7 import traceback | 7 import traceback |
8 | 8 |
9 from app_yaml_helper import AppYamlHelper | 9 from app_yaml_helper import AppYamlHelper |
10 from appengine_wrappers import ( | 10 from appengine_wrappers import ( |
11 GetAppVersion, IsDeadlineExceededError, logservice) | 11 GetAppVersion, IsDeadlineExceededError, logservice) |
12 from branch_utility import BranchUtility | 12 from branch_utility import BranchUtility |
13 from compiled_file_system import CompiledFileSystem | 13 from compiled_file_system import CompiledFileSystem |
14 from data_source_registry import CreateDataSources | 14 from data_source_registry import CreateDataSources |
15 from empty_dir_file_system import EmptyDirFileSystem | 15 from empty_dir_file_system import EmptyDirFileSystem |
16 from environment import IsDevServer | 16 from environment import IsDevServer |
17 from file_system_util import CreateURLsFromPaths | 17 from file_system_util import CreateURLsFromPaths |
18 from future import Gettable, Future | |
18 from github_file_system_provider import GithubFileSystemProvider | 19 from github_file_system_provider import GithubFileSystemProvider |
19 from host_file_system_provider import HostFileSystemProvider | 20 from host_file_system_provider import HostFileSystemProvider |
20 from object_store_creator import ObjectStoreCreator | 21 from object_store_creator import ObjectStoreCreator |
21 from render_servlet import RenderServlet | 22 from render_servlet import RenderServlet |
22 from server_instance import ServerInstance | 23 from server_instance import ServerInstance |
23 from servlet import Servlet, Request, Response | 24 from servlet import Servlet, Request, Response |
24 import svn_constants | 25 import svn_constants |
25 | 26 |
26 class _SingletonRenderServletDelegate(RenderServlet.Delegate): | 27 class _SingletonRenderServletDelegate(RenderServlet.Delegate): |
27 def __init__(self, server_instance): | 28 def __init__(self, server_instance): |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 def request_files_in_dir(path, prefix=''): | 145 def request_files_in_dir(path, prefix=''): |
145 '''Requests every file found under |path| in this host file system, with | 146 '''Requests every file found under |path| in this host file system, with |
146 a request prefix of |prefix|. | 147 a request prefix of |prefix|. |
147 ''' | 148 ''' |
148 files = [name for name, _ in CreateURLsFromPaths(trunk_fs, path, prefix)] | 149 files = [name for name, _ in CreateURLsFromPaths(trunk_fs, path, prefix)] |
149 return _RequestEachItem(path, files, render) | 150 return _RequestEachItem(path, files, render) |
150 | 151 |
151 results = [] | 152 results = [] |
152 | 153 |
153 try: | 154 try: |
155 # Run the hand-written Cron methods first; they can be run in parallel. | |
156 def run_cron_for_future(target): | |
157 title = target.__class__.__name__ | |
158 start_time = time.time() | |
159 future = target.Cron() | |
160 assert isinstance(future, Future), ( | |
161 '%s.Cron() did not return a Future' % title) | |
162 def resolve(): | |
163 try: | |
164 future.Get() | |
165 except Exception as e: | |
166 _cronlog.error('%s: error %s' % (title, traceback.format_exc())) | |
167 results.append(False) | |
168 if IsDeadlineExceededError(e): raise | |
169 finally: | |
170 _cronlog.info( | |
171 '%s: took %s seconds' % (title, time.time() - start_time)) | |
Jeffrey Yasskin
2013/11/06 22:37:09
This may not be so useful anymore since even if th
not at google - send to devlin
2013/11/11 04:08:33
Makes sense.
This logging is most for me to check
| |
172 return Future(delegate=Gettable(resolve)) | |
173 | |
174 targets = (CreateDataSources(server_instance).values() + | |
175 [server_instance.content_providers]) | |
176 title = 'running %s parallel Cron targets' % len(targets) | |
177 start_time = time.time() | |
178 _cronlog.info(title) | |
179 try: | |
180 futures = [run_cron_for_future(target) for target in targets] | |
181 for future in futures: | |
Jeffrey Yasskin
2013/11/06 22:37:09
You could delay this loop until the end of the fun
not at google - send to devlin
2013/11/11 04:08:33
Good idea.
| |
182 future.Get() | |
183 finally: | |
184 _cronlog.info('%s took %s seconds' % (title, time.time() - start_time)) | |
185 | |
154 # Rendering the public templates will also pull in all of the private | 186 # Rendering the public templates will also pull in all of the private |
155 # templates. | 187 # templates. |
156 results.append(request_files_in_dir(svn_constants.PUBLIC_TEMPLATE_PATH)) | 188 results.append(request_files_in_dir(svn_constants.PUBLIC_TEMPLATE_PATH)) |
157 | 189 |
158 # Rendering the public templates will have pulled in the .js and | 190 # Rendering the public templates will have pulled in the .js and |
159 # manifest.json files (for listing examples on the API reference pages), | 191 # manifest.json files (for listing examples on the API reference pages), |
160 # but there are still images, CSS, etc. | 192 # but there are still images, CSS, etc. |
161 results.append(request_files_in_dir(svn_constants.STATIC_PATH, | 193 results.append(request_files_in_dir(svn_constants.STATIC_PATH, |
162 prefix='static/')) | 194 prefix='static/')) |
163 | 195 |
164 # Samples are too expensive to run on the dev server, where there is no | 196 # Samples are too expensive to run on the dev server, where there is no |
165 # parallel fetch. | 197 # parallel fetch. |
166 if not IsDevServer(): | 198 if not IsDevServer(): |
167 # Fetch each individual sample file. | 199 # Fetch each individual sample file. |
168 results.append(request_files_in_dir(svn_constants.EXAMPLES_PATH, | 200 results.append(request_files_in_dir(svn_constants.EXAMPLES_PATH, |
169 prefix='extensions/examples/')) | 201 prefix='extensions/examples/')) |
170 | 202 |
171 # Fetch the zip file of each example (contains all the individual | 203 # Fetch the zip file of each example (contains all the individual |
172 # files). | 204 # files). |
173 example_zips = [] | 205 example_zips = [] |
174 for root, _, files in trunk_fs.Walk(svn_constants.EXAMPLES_PATH): | 206 for root, _, files in trunk_fs.Walk(svn_constants.EXAMPLES_PATH): |
175 example_zips.extend( | 207 example_zips.extend( |
176 root + '.zip' for name in files if name == 'manifest.json') | 208 root + '.zip' for name in files if name == 'manifest.json') |
177 results.append(_RequestEachItem( | 209 results.append(_RequestEachItem( |
178 'example zips', | 210 'example zips', |
179 example_zips, | 211 example_zips, |
180 lambda path: render('extensions/examples/' + path))) | 212 lambda path: render('extensions/examples/' + path))) |
181 | |
182 def run_cron(data_source): | |
183 title = data_source.__class__.__name__ | |
184 _cronlog.info('%s: starting' % title) | |
185 start_time = time.time() | |
186 try: | |
187 data_source.Cron() | |
188 except Exception as e: | |
189 _cronlog.error('%s: error %s' % (title, traceback.format_exc())) | |
190 results.append(False) | |
191 if IsDeadlineExceededError(e): raise | |
192 finally: | |
193 _cronlog.info( | |
194 '%s: took %s seconds' % (title, time.time() - start_time)) | |
195 | |
196 for data_source in CreateDataSources(server_instance).values(): | |
197 run_cron(data_source) | |
198 | |
199 run_cron(server_instance.content_providers) | |
200 | |
201 except: | 213 except: |
202 results.append(False) | 214 results.append(False) |
203 # This should never actually happen (each cron step does its own | 215 # This should never actually happen (each cron step does its own |
204 # conservative error checking), so re-raise no matter what it is. | 216 # conservative error checking), so re-raise no matter what it is. |
205 _cronlog.error('uncaught error: %s' % traceback.format_exc()) | 217 _cronlog.error('uncaught error: %s' % traceback.format_exc()) |
206 raise | 218 raise |
207 finally: | 219 finally: |
208 success = all(results) | 220 success = all(results) |
209 _cronlog.info('finished (%s)', 'success' if success else 'FAILED') | 221 _cronlog.info('finished (%s)', 'success' if success else 'FAILED') |
210 return (Response.Ok('Success') if success else | 222 return (Response.Ok('Success') if success else |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 branch_utility = self._delegate.CreateBranchUtility(object_store_creator) | 273 branch_utility = self._delegate.CreateBranchUtility(object_store_creator) |
262 host_file_system_provider = self._delegate.CreateHostFileSystemProvider( | 274 host_file_system_provider = self._delegate.CreateHostFileSystemProvider( |
263 object_store_creator, max_trunk_revision=revision) | 275 object_store_creator, max_trunk_revision=revision) |
264 github_file_system_provider = self._delegate.CreateGithubFileSystemProvider( | 276 github_file_system_provider = self._delegate.CreateGithubFileSystemProvider( |
265 object_store_creator) | 277 object_store_creator) |
266 return ServerInstance(object_store_creator, | 278 return ServerInstance(object_store_creator, |
267 CompiledFileSystem.Factory(object_store_creator), | 279 CompiledFileSystem.Factory(object_store_creator), |
268 branch_utility, | 280 branch_utility, |
269 host_file_system_provider, | 281 host_file_system_provider, |
270 github_file_system_provider) | 282 github_file_system_provider) |
OLD | NEW |