-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: adding course review metrics to content metadata and algolia index #735
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
|
||
from .base_oauth import BaseOAuthClient | ||
from .constants import ( | ||
DISCOVERY_COURSE_REVIEWS_ENDPOINT, | ||
DISCOVERY_COURSES_ENDPOINT, | ||
DISCOVERY_OFFSET_SIZE, | ||
DISCOVERY_PROGRAMS_ENDPOINT, | ||
|
@@ -80,6 +81,75 @@ | |
break | ||
return response.json() | ||
|
||
def _retrieve_course_reviews(self, request_params): | ||
""" | ||
Makes a request to discovery's /api/v1/course_review/ paginated endpoint | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this endpoint paginated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. locally testing it seems so? |
||
""" | ||
page = request_params.get('page', 1) | ||
LOGGER.info(f'Retrieving course reviews from course-discovery for page {page}...') | ||
attempts = 0 | ||
while True: | ||
attempts = attempts + 1 | ||
successful = True | ||
exception = None | ||
try: | ||
response = self.client.get( | ||
DISCOVERY_COURSE_REVIEWS_ENDPOINT, | ||
params=request_params, | ||
timeout=self.HTTP_TIMEOUT, | ||
) | ||
successful = response.status_code < 400 | ||
elapsed_seconds = response.elapsed.total_seconds() | ||
LOGGER.info( | ||
f'Retrieved course review results from course-discovery for page {page} in ' | ||
f'retrieve_course_reviews_seconds={elapsed_seconds} seconds.' | ||
) | ||
except requests.exceptions.RequestException as err: | ||
exception = err | ||
LOGGER.exception(f'Error while retrieving course review results from course-discovery for page {page}') | ||
successful = False | ||
if attempts <= self.MAX_RETRIES and not successful: | ||
sleep_seconds = self._calculate_backoff(attempts) | ||
LOGGER.warning( | ||
f'failed request detected from {DISCOVERY_SEARCH_ALL_ENDPOINT}, ' | ||
'backing-off before retrying, ' | ||
f'sleeping {sleep_seconds} seconds...' | ||
) | ||
time.sleep(sleep_seconds) | ||
else: | ||
if exception: | ||
raise exception | ||
break | ||
return response.json() | ||
|
||
def get_course_reviews(self, course_keys=None): | ||
""" | ||
Return results from the discovery service's /course_review endpoint as an object of key = course key, value = | ||
course review. If course_keys is specified, only return results for those course keys. | ||
""" | ||
page = 1 | ||
results = [] | ||
request_params = {'page': page} | ||
try: | ||
response = self._retrieve_course_reviews(request_params) | ||
results += response.get('results', []) | ||
# Traverse all pages and concatenate results | ||
while response.get('next'): | ||
page += 1 | ||
response = self._retrieve_course_reviews(request_params) | ||
results += response.get('results', []) | ||
except Exception as exc: | ||
LOGGER.exception(f'Could not retrieve course reviews from course-discovery (page {page}) {exc}') | ||
raise exc | ||
|
||
results = { | ||
result.get('course_key'): result for result in results if ( | ||
course_keys is None or result.get('course_key') in course_keys | ||
) | ||
} | ||
|
||
return results | ||
|
||
def get_metadata_by_query(self, catalog_query): | ||
""" | ||
Return results from the discovery service's search/all endpoint. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviews_for_courses_dict
is a list?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope-
get_course_reviews
should return a dictionary