示例#1
0
 def _prune_blob_cache(self):
     """Remove blob cache entries older than the configured number of
     days."""
     # Do this check no more than once an hour
     if datetime.now() - self._last_cache_prune < timedelta(hours=1):
         return
     self._last_cache_prune = datetime.now()
     BlobCache.prune(self.config.cachedir, self.config.blob_cache_days)
示例#2
0
 def _prune_cache_thread(self):
     '''Runs as a separate Python thread; cannot interact with Tornado
     state.'''
     while True:
         try:
             BlobCache.prune(self.blob_cache.basedir, self.blob_cache_days)
         except Exception:
             _log.exception('Pruning blob cache')
         try:
             self.search_cache.prune()
         except Exception:
             _log.exception('Pruning search cache')
         time.sleep(self.cache_prune_interval)
示例#3
0
 def _prune_cache_thread(self):
     '''Runs as a separate Python thread; cannot interact with Tornado
     state.'''
     while True:
         try:
             BlobCache.prune(self.blob_cache.basedir, self.blob_cache_days)
         except Exception:
             _log.exception('Pruning blob cache')
         try:
             self.search_cache.prune()
         except Exception:
             _log.exception('Pruning search cache')
         time.sleep(self.cache_prune_interval)
示例#4
0
    def __init__(self, **kwargs):
        if options.baseurl is None:
            raise ValueError('Base URL must be configured')

        router = SockJSRouter(SearchConnection, '/search',
                              self.sockjs_settings)
        # Allow connections to find the application
        router.application = self

        handlers = list(self.handlers)
        router.apply_routes(handlers)
        settings = dict(self.app_settings)
        settings.update(kwargs)
        tornado.web.Application.__init__(self, handlers, **settings)

        if not os.path.isdir(options.blob_cache_dir):
            os.makedirs(options.blob_cache_dir, 0700)
        self.blob_cache = BlobCache(options.blob_cache_dir)

        self.search_cache = SearchCache(options.search_cache_dir)

        self._pruner = threading.Thread(target=self._prune_cache_thread,
                                        name='prune-cache')
        self._pruner.daemon = True
        self._pruner.start()