This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/workers/gc/gcworker.py
Jimmy Zelinskie 4bf4ce33c9 util/metrics: remove metricqueue abstraction
This change replaces the metricqueue library with a native Prometheus
client implementation with the intention to aggregated results with the
Prometheus PushGateway.

This change also adds instrumentation for greenlet context switches.
2019-11-21 12:53:09 -05:00

51 lines
1.6 KiB
Python

import logging
import time
import features
from app import app
from data.database import UseThenDisconnect
from data.model.repository import find_repository_with_garbage, get_random_gc_policy
from data.model.gc import garbage_collect_repo
from workers.worker import Worker
logger = logging.getLogger(__name__)
class GarbageCollectionWorker(Worker):
def __init__(self):
super(GarbageCollectionWorker, self).__init__()
self.add_operation(self._garbage_collection_repos,
app.config.get('GARBAGE_COLLECTION_FREQUENCY', 30))
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)
if __name__ == "__main__":
if not features.GARBAGE_COLLECTION:
logger.debug('Garbage collection is disabled; skipping')
while True:
time.sleep(100000)
if ((app.config.get('V3_UPGRADE_MODE') == 'production-transition') or
(app.config.get('V3_UPGRADE_MODE') == 'post-oci-rollout') or
(app.config.get('V3_UPGRADE_MODE') == 'post-oci-roll-back-compat')):
logger.debug('GC worker disabled for production transition; skipping')
while True:
time.sleep(100000)
worker = GarbageCollectionWorker()
worker.start()