Commit 110a6e0b by Eric Fischer Committed by GitHub

Merge pull request #69 from edx/efischer/now_where_were_we

Return to normalcy
parents 947777f3 207575dd
...@@ -2,5 +2,5 @@ dogapi>=1.2.1,<2.0.0 ...@@ -2,5 +2,5 @@ dogapi>=1.2.1,<2.0.0
django-model-utils>=2.3.1,<3.0.0 django-model-utils>=2.3.1,<3.0.0
# Use the same DRF version as edx-platform # Use the same DRF version as edx-platform
git+https://github.com/edx/django-rest-framework.git@1ceda7c086fddffd1c440cc86856441bbf0bd9cb#egg=djangorestframework==3.6.3 git+https://github.com/edx/django-rest-framework.git@1ceda7c086fddffd1c440cc86856441bbf0bd9cb#egg=djangorestframework==3.6.3
jsonfield>=1.0.3,<2.0.0 jsonfield>=2.0.2,<3.0.0
pytz pytz
...@@ -33,7 +33,7 @@ def load_requirements(*requirements_paths): ...@@ -33,7 +33,7 @@ def load_requirements(*requirements_paths):
setup( setup(
name='edx-submissions', name='edx-submissions',
version='2.0.9', version='2.0.10',
author='edX', author='edX',
description='An API for creating submissions and scores.', description='An API for creating submissions and scores.',
url='http://github.com/edx/edx-submissions.git', url='http://github.com/edx/edx-submissions.git',
......
...@@ -10,6 +10,7 @@ EDUCATOR-1090 ...@@ -10,6 +10,7 @@ EDUCATOR-1090
""" """
import logging import logging
import time
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.db import transaction from django.db import transaction
...@@ -24,21 +25,43 @@ class Command(BaseCommand): ...@@ -24,21 +25,43 @@ class Command(BaseCommand):
""" """
help = 'Loads and saves all Submissions objects to force new non-hyphenated uuid values on disk.' help = 'Loads and saves all Submissions objects to force new non-hyphenated uuid values on disk.'
def add_arguments(self, parser):
"""
Add arguments to the command parser.
Uses argparse syntax. See documentation at
https://docs.python.org/3/library/argparse.html.
"""
parser.add_argument(
'--start', '-s',
default=0,
help=u"The Submission.id at which to begin updating rows. 0 by default."
)
parser.add_argument(
'--chunk', '-c',
default=1000,
help=u"Batch size, how many rows to update in a given transaction. Default 1000.",
)
parser.add_argument(
'--wait', '-w',
default=2,
help=u"Wait time between transactions, in seconds. Default 2.",
)
def handle(self, *args, **options): def handle(self, *args, **options):
""" """
By default, we're going to do this in chunks. This way, if there ends up being an error, By default, we're going to do this in chunks. This way, if there ends up being an error,
we can check log messages and continue from that point after fixing the issue. we can check log messages and continue from that point after fixing the issue.
""" """
START_VALUE = 0
CHUNK_SIZE = 1000
total_len = Submission.objects.count() total_len = Submission.objects.count()
log.info("Beginning uuid update, {} rows exist in total") log.info("Beginning uuid update, {} rows exist in total".format(total_len))
current = START_VALUE; current = options['start'];
while current < total_len: while current < total_len:
end_chunk = current + CHUNK_SIZE end_chunk = current + options['chunk'] if total_len - options['chunk'] >= current else total_len
log.info("Updating entries {} to {}".format(current, end_chunk)) log.info("Updating entries in range [{}, {})".format(current, end_chunk))
with transaction.atomic(): with transaction.atomic():
for submission in Submission.objects.filter(id__gte=current, id__lt=end_chunk).iterator(): for submission in Submission.objects.filter(id__gte=current, id__lt=end_chunk).iterator():
submission.save(update_fields=['uuid']) submission.save(update_fields=['uuid'])
current = current + CHUNK_SIZE time.sleep(options['wait'])
current = current + options['chunk']
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment