Skip to content
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

ENT-2310 | Adding a post_save receiver to listen to CourseEnrollments… #589

Merged
merged 1 commit into from
Oct 2, 2019

Conversation

christopappas
Copy link
Contributor

@christopappas christopappas commented Sep 27, 2019

… table

Before I merged, I definitely want to make sure I can verify that the async element of this will work on Production... will want to mess around a bit more with Devstack to that end.

This works in devstack with CELERY_ALWAYS_EAGER=True, meaning that tasks run synchronously. Production and staging environment configs are different enough from devstack that I'm not 100% convinced testing asynchronous functionality means this code will or will not work in production, though I will still test setting up a broker and worker locally to prove the concept.

Barring discovering anything that drastically changes my approach, this should be ready for review!

Merge checklist:

  • Any new requirements are in the right place (do not manually modify the requirements/*.txt files)
    • base.in if needed in production but edx-platform doesn't install it
    • test-master.in if edx-platform pins it, with a matching version
    • make upgrade && make requirements have been run to regenerate requirements
  • make static has been run to update webpack bundling if any static content was updated
  • Version bumped
  • Changelog record added
  • Translations updated

Post merge:

  • Tag pushed and a new version released
  • Version pushed to PyPI
  • PR created in edx-platform to upgrade dependencies (including edx-enterprise)

"Creating EnterpriseCourseEnrollment for user %s "
"on course %s for enterprise_customer %s"
), enterprise_customer_user.user_id, course_id, enterprise_customer)
EnterpriseCourseEnrollment.objects.create(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use a get_or_create here just to be safe? (so we don't create duplicates)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clicking enroll in devstack did NOT create 2 enterprise course enrollments, so i do not think this is necessary

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good question. Even though in testing with devstack, it did not create 2 enterprise course enrollments... I feel that it might be good to be safe here just in case with get_or_create. If there are any edge cases where an enrollment might already exist in stage/production data, might be good to proactively handle that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some of the enrollment saves that trigger this will be from existing enterprise enrollment workflows, so it is definitely possible that the enterprise course enrollment already exists. you might want to check for its existence before making the catalog call.

enterprise/signals.py Show resolved Hide resolved
"Creating EnterpriseCourseEnrollment for user %s "
"on course %s for enterprise_customer %s"
), enterprise_customer_user.user_id, course_id, enterprise_customer)
EnterpriseCourseEnrollment.objects.create(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good question. Even though in testing with devstack, it did not create 2 enterprise course enrollments... I feel that it might be good to be safe here just in case with get_or_create. If there are any edge cases where an enrollment might already exist in stage/production data, might be good to proactively handle that.

"""
self.user = UserFactory(id=2, email='user@example.com')
self.enterprise_customer = EnterpriseCustomerFactory(
name='Team Titans',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice enterprise customer name ;)

Copy link
Contributor

@brittneyexline brittneyexline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good overall, just one comment.
another thing that i was thinking, though it may be overly cautious, is to put this behind a waffle flag so we can control when we turn it on and monitor it more closely. it could be overkill and then we'd have to clean up the flag later, but given the unpredictable nature of edx platform releases, it would allow us to have more control over when this is really getting turned on. food for thought :-)

"Creating EnterpriseCourseEnrollment for user %s "
"on course %s for enterprise_customer %s"
), enterprise_customer_user.user_id, course_id, enterprise_customer)
EnterpriseCourseEnrollment.objects.create(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some of the enrollment saves that trigger this will be from existing enterprise enrollment workflows, so it is definitely possible that the enterprise course enrollment already exists. you might want to check for its existence before making the catalog call.

@christopappas
Copy link
Contributor Author

The task will not be kicked off if created is not True in the signal though. So it's not just a save that has to happen for this task to be run, but a create on the CourseEnrollment table

Would there ever be a case where there would be more than 1 course enrollment created that maps to a single enterpriseCourseEnrollment? If not, I think this would be fine, right?

@christopappas
Copy link
Contributor Author

@brittneyexline 🔼

@brittneyexline
Copy link
Contributor

i'm saying that if the EnterpriseCourseEnrollment record had already been created at the point that the task has been kicked off, something that is definitely possible for the current enterprise enrollment workflow (see https://github.com/edx/edx-enterprise/blob/master/enterprise/models.py#L760), then we could bypass doing the work of in the task in this case too.

@christopappas
Copy link
Contributor Author

Ah, I see. Update coming

@christopappas
Copy link
Contributor Author

@brittneyexline addressed your recommendation. updated to make sure we check if the EnterpriseCourseEnrollment exists before making the call to discovery (and added a test)

… table

Adding in a test file I forgot. Updating a few test doctrings

Actually adding in the tasks file too

Updating task to prevent duplicate recreation of EnterpriseCourseEnrollment

Appeasing pylint

bumping version
@christopappas christopappas merged commit efe35de into master Oct 2, 2019
@christopappas christopappas deleted the cpappas/ENT-2310 branch October 2, 2019 16:51
sameenfatima78 pushed a commit to sameenfatima78/edx-enterprise that referenced this pull request Nov 21, 2019
… table (openedx#589)

Adding in a test file I forgot. Updating a few test doctrings

Actually adding in the tasks file too

Updating task to prevent duplicate recreation of EnterpriseCourseEnrollment

Appeasing pylint

bumping version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants