Make namespace deletion asynchronous
Instead of deleting a namespace synchronously as before, we now mark the namespace for deletion, disable it, and rename it. A worker then comes along and deletes the namespace in the background. This results in a *significantly* better user experience, as the namespace deletion operation now "completes" in under a second, where before it could take 10s of minutes at the worse. Fixes https://jira.coreos.com/browse/QUAY-838
This commit is contained in:
parent
d9015a1863
commit
8bc55a5676
21 changed files with 244 additions and 129 deletions
|
@ -1,52 +0,0 @@
|
|||
import logging
|
||||
import sys
|
||||
|
||||
from app import app
|
||||
from data import model
|
||||
from data.database import Repository, User
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def delete_summary(username):
|
||||
found = User.get(User.username == username)
|
||||
dependencies = found.dependencies(search_nullable=False)
|
||||
counts = {}
|
||||
for expression, field in dependencies:
|
||||
use_count = field.model_class.select().where(expression).count()
|
||||
if use_count > 0:
|
||||
counts[field.model_class.__name__] = use_count
|
||||
|
||||
return counts
|
||||
|
||||
|
||||
def delete_username(username):
|
||||
# First delete the repositories owned by this user
|
||||
found = User.get(User.username == username)
|
||||
for repository in list(Repository.select().where(Repository.namespace_user == found)):
|
||||
print 'Deleting repository: {0}/{1}'.format(found.username, repository.name)
|
||||
model.repository.purge_repository(found.username, repository.name)
|
||||
|
||||
# Now recursively delete user, which will clean up all non-nullable referencing fields
|
||||
print 'Deleting user: {0}'.format(username)
|
||||
found.delete_instance(recursive=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
summary = delete_summary(sys.argv[1]).items()
|
||||
|
||||
if summary:
|
||||
print 'Will delete:'
|
||||
for model_name, count in summary:
|
||||
print '{0}: {1}'.format(model_name, count)
|
||||
else:
|
||||
print 'Nothing references user.'
|
||||
|
||||
print 'Delete? [y/n]'
|
||||
delete_yn = raw_input().lower().strip()
|
||||
if delete_yn == 'y':
|
||||
delete_username(sys.argv[1])
|
||||
else:
|
||||
print 'Aborted!'
|
Reference in a new issue