Change GC worker to use data interface
This commit is contained in:
parent
38f1752a2d
commit
420a5e5a3a
4 changed files with 45 additions and 15 deletions
|
@ -1,13 +1,8 @@
|
||||||
import logging
|
|
||||||
|
|
||||||
from app import app
|
from app import app
|
||||||
from data.model.repository import (find_repository_with_garbage, garbage_collect_repo,
|
from data.database import UseThenDisconnect
|
||||||
get_random_gc_policy)
|
from workers.gcworker.models_pre_oci import pre_oci_model as model
|
||||||
|
|
||||||
from workers.worker import Worker
|
from workers.worker import Worker
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
class GarbageCollectionWorker(Worker):
|
class GarbageCollectionWorker(Worker):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(GarbageCollectionWorker, self).__init__()
|
super(GarbageCollectionWorker, self).__init__()
|
||||||
|
@ -16,14 +11,8 @@ class GarbageCollectionWorker(Worker):
|
||||||
|
|
||||||
def _garbage_collection_repos(self):
|
def _garbage_collection_repos(self):
|
||||||
""" Performs garbage collection on repositories. """
|
""" Performs garbage collection on repositories. """
|
||||||
repository = find_repository_with_garbage(get_random_gc_policy())
|
with UseThenDisconnect(app.config):
|
||||||
if repository is None:
|
model.perform_garbage_collection()
|
||||||
logger.debug('No repository with garbage found')
|
|
||||||
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)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
worker = GarbageCollectionWorker()
|
worker = GarbageCollectionWorker()
|
||||||
|
|
13
workers/gcworker/models_interface.py
Normal file
13
workers/gcworker/models_interface.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
from abc import ABCMeta, abstractmethod
|
||||||
|
|
||||||
|
from six import add_metaclass
|
||||||
|
|
||||||
|
@add_metaclass(ABCMeta)
|
||||||
|
class GCWorkerDataInterface(object):
|
||||||
|
"""
|
||||||
|
Interface that represents all data store interactions required by the GC worker.
|
||||||
|
"""
|
||||||
|
@abstractmethod
|
||||||
|
def perform_garbage_collection(self):
|
||||||
|
""" Performs garbage collection on a single repository, if any can be found with garbage. """
|
||||||
|
pass
|
21
workers/gcworker/models_pre_oci.py
Normal file
21
workers/gcworker/models_pre_oci.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from data.model.repository import (find_repository_with_garbage, garbage_collect_repo,
|
||||||
|
get_random_gc_policy)
|
||||||
|
|
||||||
|
from workers.gcworker.models_interface import GCWorkerDataInterface
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class PreOCIModel(GCWorkerDataInterface):
|
||||||
|
def perform_garbage_collection(self):
|
||||||
|
repository = find_repository_with_garbage(get_random_gc_policy())
|
||||||
|
if repository is None:
|
||||||
|
logger.debug('No repository with garbage found')
|
||||||
|
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)
|
||||||
|
|
||||||
|
pre_oci_model = PreOCIModel()
|
7
workers/gcworker/test/test_gcworker.py
Normal file
7
workers/gcworker/test/test_gcworker.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
from workers.gcworker.gcworker import GarbageCollectionWorker
|
||||||
|
|
||||||
|
from test.fixtures import *
|
||||||
|
|
||||||
|
def test_gc(initialized_db):
|
||||||
|
worker = GarbageCollectionWorker()
|
||||||
|
worker._garbage_collection_repos()
|
Reference in a new issue