-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbackpopulate_mit_edx_files.py
44 lines (37 loc) · 1.46 KB
/
backpopulate_mit_edx_files.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""Management command for populating MITx course run file data"""
from django.conf import settings
from django.core.management import BaseCommand
from learning_resources.tasks import import_all_mit_edx_files
from main.utils import now_in_utc
class Command(BaseCommand):
"""Populate MIT edX course run files"""
help = "Populate MIT edX course run files"
def add_arguments(self, parser):
parser.add_argument(
"-c",
"--chunk-size",
dest="chunk_size",
default=settings.LEARNING_COURSE_ITERATOR_CHUNK_SIZE,
type=int,
help="Chunk size for batch import task",
)
parser.add_argument(
"--overwrite",
dest="force_overwrite",
action="store_true",
help="Overwrite any existing records",
)
def handle(self, *args, **options): # noqa: ARG002
"""Run Populate MIT edX course run files"""
chunk_size = options["chunk_size"]
task = import_all_mit_edx_files.delay(
chunk_size=chunk_size, overwrite=options["force_overwrite"]
)
self.stdout.write(f"Started task {task} to get MIT edX course run file data")
self.stdout.write("Waiting on task...")
start = now_in_utc()
task.get()
total_seconds = (now_in_utc() - start).total_seconds()
self.stdout.write(
f"Population of MIT edX file data finished, took {total_seconds} seconds"
)