def _garbage_collection_repos(self, skip_lock_for_testing=False): """ Performs garbage collection on repositories. """ with UseThenDisconnect(app.config): policy = get_random_gc_policy() if policy is None: logger.debug("No GC policies found") return repo_ref = registry_model.find_repository_with_garbage(policy) if repo_ref is None: logger.debug("No repository with garbage found") return assert features.GARBAGE_COLLECTION try: with GlobalLock( "REPO_GARBAGE_COLLECTION_%s" % repo_ref.id, lock_ttl=REPOSITORY_GC_TIMEOUT + LOCK_TIMEOUT_PADDING, ) if not skip_lock_for_testing else empty_context(): try: repository = Repository.get(id=repo_ref.id) except Repository.DoesNotExist: return logger.debug("Starting GC of repository #%s (%s)", repository.id, repository.name) garbage_collect_repo(repository) logger.debug("Finished GC of repository #%s (%s)", repository.id, repository.name) except LockNotAcquiredException: logger.debug( "Could not acquire repo lock for garbage collection")
def _garbage_collection_repos(self): """ Performs garbage collection on repositories. """ with UseThenDisconnect(app.config): repository = find_repository_with_garbage(get_random_gc_policy()) if repository is None: logger.debug('No repository with garbage found') return assert features.GARBAGE_COLLECTION logger.debug('Starting GC of repository #%s (%s)', repository.id, repository.name) garbage_collect_repo(repository) logger.debug('Finished GC of repository #%s (%s)', repository.id, repository.name)