Commit feb87a8a by christopher lee Committed by Christopher Lee

Add wait time to courses api for refresh_course_metadata

LEARNER-5560
parent ede1cb24
...@@ -8,7 +8,9 @@ from django.db import DatabaseError, connection, transaction ...@@ -8,7 +8,9 @@ from django.db import DatabaseError, connection, transaction
from django.http import Http404, JsonResponse from django.http import Http404, JsonResponse
from django.shortcuts import redirect from django.shortcuts import redirect
from django.views.generic import View from django.views.generic import View
from course_discovery.apps.core.constants import Status from course_discovery.apps.core.constants import Status
try: try:
import newrelic.agent import newrelic.agent
except ImportError: # pragma: no cover except ImportError: # pragma: no cover
......
import concurrent.futures import concurrent.futures
import logging import logging
import math import math
import time
from decimal import Decimal from decimal import Decimal
from io import BytesIO from io import BytesIO
...@@ -84,9 +85,21 @@ class CoursesApiDataLoader(AbstractDataLoader): ...@@ -84,9 +85,21 @@ class CoursesApiDataLoader(AbstractDataLoader):
with concurrent.futures.ThreadPoolExecutor(max_workers=self.max_workers) as executor: # pragma: no cover with concurrent.futures.ThreadPoolExecutor(max_workers=self.max_workers) as executor: # pragma: no cover
if self.is_threadsafe: if self.is_threadsafe:
for page in pagerange: for page in pagerange:
# This time.sleep is to make it very likely that this method does not encounter a 429 status
# code by increasing the amount of time between each code. More details at LEARNER-5560
# The current crude estimation is for ~3000 courses with a PAGE_SIZE=50 which means this method
# will take ~30 minutes.
# TODO Ticket to gracefully handle 429 https://openedx.atlassian.net/browse/LEARNER-5565
time.sleep(30)
executor.submit(self._load_data, page) executor.submit(self._load_data, page)
else: else:
for future in [executor.submit(self._make_request, page) for page in pagerange]: for future in [executor.submit(self._make_request, page) for page in pagerange]:
# This time.sleep is to make it very likely that this method does not encounter a 429 status
# code by increasing the amount of time between each code. More details at LEARNER-5560
# The current crude estimation is for ~3000 courses with a PAGE_SIZE=50 which means this method
# will take ~30 minutes.
# TODO Ticket to gracefully handle 429 https://openedx.atlassian.net/browse/LEARNER-5565
time.sleep(30)
response = future.result() response = future.result()
self._process_response(response) self._process_response(response)
......
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