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

Side by Side Diff: chrome/common/extensions/docs/server2/content_providers.py

Issue 575613003: Docserver: Gitiles auth and cron refactoring. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 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 os 6 import os
7 import traceback 7 import traceback
8 8
9 from chroot_file_system import ChrootFileSystem 9 from chroot_file_system import ChrootFileSystem
10 from content_provider import ContentProvider 10 from content_provider import ContentProvider
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 return None 163 return None
164 164
165 return ContentProvider(name, 165 return ContentProvider(name,
166 self._compiled_fs_factory, 166 self._compiled_fs_factory,
167 file_system, 167 file_system,
168 self._object_store_creator, 168 self._object_store_creator,
169 default_extensions=default_extensions, 169 default_extensions=default_extensions,
170 supports_templates=supports_templates, 170 supports_templates=supports_templates,
171 supports_zip=supports_zip) 171 supports_zip=supports_zip)
172 172
173 def Cron(self): 173 def GetRefreshPaths(self):
174 return self._GetConfig().keys()
175
176 def Refresh(self, path):
174 def safe(name, action, callback): 177 def safe(name, action, callback):
175 '''Safely runs |callback| for a ContentProvider called |name| by 178 '''Safely runs |callback| for a ContentProvider called |name| by
176 swallowing exceptions and turning them into a None return value. It's 179 swallowing exceptions and turning them into a None return value. It's
177 important to run all ContentProvider Crons even if some of them fail. 180 important to run all ContentProvider Refreshes even if some of them fail.
178 ''' 181 '''
179 try: 182 try:
180 return callback() 183 return callback()
181 except: 184 except:
182 if not _IGNORE_MISSING_CONTENT_PROVIDERS[0]: 185 if not _IGNORE_MISSING_CONTENT_PROVIDERS[0]:
183 logging.error('Error %s Cron for ContentProvider "%s":\n%s' % 186 logging.error('Error %s Refresh for ContentProvider "%s":\n%s' %
184 (action, name, traceback.format_exc())) 187 (action, name, traceback.format_exc()))
185 return None 188 return None
186 189
187 futures = [(name, safe(name, 190 config = self._GetConfig()[path]
188 'initializing', 191 provider = self._CreateContentProvider(path, config)
189 self._CreateContentProvider(name, config).Cron)) 192 future = safe(path,
190 for name, config in self._GetConfig().iteritems()] 193 'initializing',
191 return Future(callback= 194 self._CreateContentProvider(path, config).Refresh)
192 lambda: [safe(name, 'resolving', f.Get) for name, f in futures if f]) 195 if future is None:
196 return Future(callback=lambda: True)
197 return Future(callback=lambda: safe(path, 'resolving', future.Get))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698