Unify the database connection lifecycle across all workers
This commit is contained in:
parent
38cb63d195
commit
2f626f2691
7 changed files with 111 additions and 130 deletions
|
@ -1,7 +1,6 @@
|
|||
import logging
|
||||
|
||||
from app import app
|
||||
from data.database import UseThenDisconnect
|
||||
from data.model.repository import find_repository_with_garbage, garbage_collect_repo
|
||||
from workers.worker import Worker
|
||||
|
||||
|
@ -14,17 +13,15 @@ class GarbageCollectionWorker(Worker):
|
|||
|
||||
def _garbage_collection_repos(self):
|
||||
""" Performs garbage collection on repositories. """
|
||||
with UseThenDisconnect(app.config):
|
||||
repository = find_repository_with_garbage()
|
||||
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)
|
||||
repository = find_repository_with_garbage()
|
||||
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)
|
||||
|
||||
if __name__ == "__main__":
|
||||
worker = GarbageCollectionWorker()
|
||||
worker.start()
|
||||
|
|
Reference in a new issue