def run(self, *args, **kwargs): self.reset(kwargs.get('artifacts')) # Trigger handlers and return if there was an error exceptions, results = self.trigger(None, *args, **kwargs) if not all(results): self.update_status(False) return False # Create "http" cache for this task cache_key = 'http.%s.%s' % (self.get_sid(), self.key) cache = CacheManager.open(cache_key) with Plex.configuration.cache(http=cache): # Trigger children and return if there was an error exceptions, results = self.trigger_children(*args, **kwargs) # Discard HTTP cache CacheManager.delete(cache_key) if not all(results): self.update_status(False, exceptions=exceptions) return False self.update_status(True) return True
def CacheStatisticsMenu(): oc = ObjectContainer(title2="Cache Statistics") for item in CacheManager.statistics(): oc.add(DirectoryObject( key='', title=pad_title("[%s] Cache Size: %s, Store Size: %s" % item) )) return oc
def init_plex(): # plex.py Plex.configuration.defaults.authentication( os.environ.get('PLEXTOKEN') ) # plex.activity.py path = os.path.join(Core.log.handlers[1].baseFilename, '..', '..', 'Plex Media Server.log') path = os.path.abspath(path) Activity['logging'].add_hint(path) # plex.metadata.py Metadata.configure( cache=CacheManager.get('metadata'), client=Plex.client )
def initialize(cls): cls.thread = threading.Thread(target=cls.run, name="SyncManager") cls.lock = threading.Lock() cls.handlers = dict([(h.key, h(cls)) for h in HANDLERS]) cls.statistics = SyncStatistics(cls) # Load/setup matcher cache Plex.configuration.defaults.cache( matcher=CacheManager.get('matcher', persistent=True) ) # Bind activity events Activity.on('websocket.scanner.finished', cls.scanner_finished) EG['SyncManager.current'].set(lambda: cls.current) cls.initialized = True
success = False try: success = handler.run(section=section, **kwargs) except CancelException, e: handler.update_status(False) log.info('Task "%s" was cancelled', key) except Exception, ex: handler.update_status(False) log.error('Exception raised in handler for %r: %s', key, ex, exc_info=True) log.debug( 'Cache Statistics - len(matcher): %s, len(metadata): %s', len(CacheManager.get('matcher')), len(CacheManager.get('metadata')) ) # Sync "matcher" cache (back to disk) CacheManager.get('matcher').sync() # Clear memory caches CacheManager.get('matcher').cache.clear() CacheManager.get('metadata').cache.clear() # Run garbage collection log.debug('[GC] Collected %d objects', gc.collect()) log.debug('[GC] Count: %s', gc.get_count()) log.debug('[GC] Garbage: %s', len(gc.garbage))