-
Notifications
You must be signed in to change notification settings - Fork 4.2k
fix: make discovery service dependency optional for discussion notifications #37039
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,11 +6,24 @@ | |
|
|
||
| from datetime import timedelta | ||
|
|
||
| from django.conf import settings | ||
| from openedx.core.djangoapps.catalog.utils import get_course_run_details | ||
| from openedx.core.djangoapps.catalog.models import CatalogIntegration | ||
|
|
||
| MIN_DURATION = timedelta( | ||
| weeks=getattr(settings, 'COURSE_DURATION_MIN_WEEKS', 4) | ||
| ) | ||
| MAX_DURATION = timedelta( | ||
| weeks=getattr(settings, 'COURSE_DURATION_MAX_WEEKS', 18) | ||
| ) | ||
|
|
||
| MIN_DURATION = timedelta(weeks=4) | ||
| MAX_DURATION = timedelta(weeks=18) | ||
|
|
||
| def catalog_integration_enabled(): | ||
| """ | ||
| Check if catalog integration is enabled | ||
| """ | ||
| catalog_integration = CatalogIntegration.current() | ||
|
Contributor
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. I don't have an issue with this per se, but wouldn't it be clearer to test the setting that enables catalog integration?
Contributor
Author
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. I only found this setting related to catalog existence on which we could place a check COURSE_CATALOG_API_URL. The setting has a default value that's always present even when Discovery isn't running, so checking it alone might incorrectly return The CatalogIntegration.is_enabled() method, on the other hand is consistent with how other catalog functions determine enablement throughout the codebase and also seems to provides proper administrative control through the database. |
||
| return catalog_integration.is_enabled() | ||
|
|
||
|
|
||
| def get_expected_duration(course_id): | ||
|
|
@@ -20,12 +33,13 @@ def get_expected_duration(course_id): | |
|
|
||
| access_duration = MIN_DURATION | ||
|
|
||
| # The user course expiration date is the content availability date | ||
| # plus the weeks_to_complete field from course-discovery. | ||
| discovery_course_details = get_course_run_details(course_id, ['weeks_to_complete']) | ||
| expected_weeks = discovery_course_details.get('weeks_to_complete') | ||
| if expected_weeks: | ||
| access_duration = timedelta(weeks=expected_weeks) | ||
| if catalog_integration_enabled(): | ||
| discovery_course_details = get_course_run_details( | ||
| course_id, ['weeks_to_complete'] | ||
| ) | ||
| expected_weeks = discovery_course_details.get('weeks_to_complete') | ||
| if expected_weeks: | ||
| access_duration = timedelta(weeks=expected_weeks) | ||
|
|
||
| # Course access duration is bounded by the min and max duration. | ||
| access_duration = max(MIN_DURATION, min(MAX_DURATION, access_duration)) | ||
|
|
||
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.
Can you clarify in the PR description that
MIN_DURATIONandMAX_DURATIONare currently hard-coded to 4 weeks and 18 weeks respectively, and that this PR makes them configurable?I feel like this is going to require some input from the product working group, but having this context will help.
Uh oh!
There was an error while loading. Please reload this page.
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.
@pdpinch Updated in the additional changes section