-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Handle completion events #16112
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
Merged
jcdyer
merged 1 commit into
openedx:master
from
open-craft:cliff/handle-completion-events
Oct 25, 2017
Merged
Handle completion events #16112
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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| """ | ||
| This module contains various configuration settings via | ||
| waffle switches for the completion app. | ||
| """ | ||
| from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
|
||
| from openedx.core.djangoapps.waffle_utils import WaffleSwitchNamespace | ||
|
|
||
| # Namespace | ||
| WAFFLE_NAMESPACE = 'completion' | ||
|
|
||
| # Switches | ||
| ENABLE_COMPLETION_TRACKING = 'enable_completion_tracking' | ||
|
|
||
|
|
||
| def waffle(): | ||
| """ | ||
| Returns the namespaced, cached, audited Waffle class for completion. | ||
| """ | ||
| return WaffleSwitchNamespace(name=WAFFLE_NAMESPACE, log_prefix='completion: ') | ||
This file contains hidden or 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.
@jcdyer: The old Mercury team tended to use Waffle Flags (rather than switches) for everything. I like that the flags enable you to turn things on for single users, or beta-testers, or an individual course (see CourseWaffleFlag), that isn't available with switches. Also, I think our waffle_utils code for flags is a bit cleaner than with switches.
Would you mind reviewing some of the flags here and let let me know what you think?
https://github.com/edx/edx-platform/blob/5ae2bee17f77e345fadef3a0935dc85a890ec405/openedx/features/course_experience/__init__.py
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.
Unless I misunderstand something, waffle flags require a request object to be present. A lot of this code is happening in signals and on models, and so doesn't have a request available. Would you recommend refactoring to block things at the view level or passing a fake request object with the relevant user attached to it?
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.
We had debated using
RequestCache.get_current_request()internally and takingrequestout of the signature, but wanted to continue to make this explicit.Would it work to use
RequestCache.get_current_request()? I've seen a couple of other examples of using the request cache in models.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.
Unless you think it's very important, I'd rather not do that. Another client had me spend the last several weeks removing code that was doing something similar in a different codebase, because it was making refactoring and testing a nightmare. There isn't always a current request available (tests, celery tasks, and management commands are three examples), and then to use any of this code in any of those contexts, a fake request needs to be set up by the caller and injected into the request cache. Worse, the fact that this is needed is not evident from the signatures of the methods that check the waffle flag, so you can't work with the code without intimate knowledge of its internals.
If we have enough information available inside all the contexts where the flag is checked to be able to create a fake response inside the public interfaces, then it would make sense. I haven't looked closely enough at waffle to know exactly what it needs from a request. I know we'll have a user and a course available, because it's already part of the submit_completion signature. But I don't know if that's enough, or if not, how much extra work it will be to create a suitable request.
A waffle switch gives us the simple ability to turn the feature on and off without the extra complication, and my understanding was that this was all we needed for this--to be sure we don't start saving data until the feature is complete (or complete enough).
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.
Got it. A switch covers the most important need for now, and hopefully the only need. :)