70de107268
This change adds a worker to conduct GC on repositories with garbage every 10s. Fixes #144
30 lines
993 B
Python
30 lines
993 B
Python
import logging
|
|
|
|
from apscheduler.schedulers.blocking import BlockingScheduler
|
|
|
|
from app import app
|
|
from data.database import UseThenDisconnect
|
|
from data.model.repository import find_repository_with_garbage, garbage_collect_repo
|
|
|
|
logger = logging.getLogger(__name__)
|
|
sched = BlockingScheduler()
|
|
|
|
@sched.scheduled_job(trigger='interval', seconds=10)
|
|
def garbage_collect_repositories():
|
|
""" Performs garbage collection on repositories. """
|
|
|
|
with UseThenDisconnect(app.config):
|
|
repository = find_repository_with_garbage(app.config.get('EXP_ASYNC_GARBAGE_COLLECTION', []))
|
|
if repository is None:
|
|
logger.debug('No repository with garbage found')
|
|
return False
|
|
|
|
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)
|
|
return True
|
|
|
|
|
|
if __name__ == "__main__":
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
sched.start()
|