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/tools/backfillplacements.py
2014-06-18 13:01:12 -04:00

26 lines
830 B
Python

import logging
logging.basicConfig(level=logging.DEBUG)
from data.database import ImageStorage, ImageStoragePlacement, ImageStorageLocation
from peewee import *
from app import app
logger = logging.getLogger(__name__)
GROUP_SIZE = 1000
storage_needing_placements = (ImageStorage
.select()
.join(ImageStoragePlacement, JOIN_LEFT_OUTER)
.group_by(ImageStorage)
.having(fn.Count(ImageStoragePlacement.id) == 0))
default_location = ImageStorageLocation.get(name=app.config['DS_BACKFILL_LOCATION'])
while storage_needing_placements.count() > 0:
logger.debug('Starting group of %s', GROUP_SIZE)
for needs_placement in list(storage_needing_placements.limit(GROUP_SIZE)):
logger.debug('Adding placement: %s', needs_placement.id)
ImageStoragePlacement.create(storage=needs_placement, location=default_location)