Skip to content

feat: add instructor task for async batch enrollment#37216

Merged
MaferMazu merged 19 commits into
openedx:masterfrom
eduNEXT:bav/add-instructor-task-for-async-batch-enrollment
May 13, 2026
Merged

feat: add instructor task for async batch enrollment#37216
MaferMazu merged 19 commits into
openedx:masterfrom
eduNEXT:bav/add-instructor-task-for-async-batch-enrollment

Conversation

@BryanttV
Copy link
Copy Markdown
Contributor

@BryanttV BryanttV commented Aug 16, 2025

Description

This PR introduces asynchronous support for Batch Enrollment/Unenrollment in the Instructor Dashboard. The goal is to address scalability limitations of the current synchronous process, which is prone to timeouts when handling large groups of learners.

Motivation

Currently, batch enrollment/unenrollment is only available in synchronous mode. For large enroll/unenroll lists, this process may time out, causing failures and reliability issues. With this change, instructors can optionally select an async mode, which processes enrolls/unenrolls in the background, avoids timeouts, and provides better progress tracking and notifications.

Implementation Details

  • Added a new checkbox "Process asynchronously" in the Batch Enrollment UI (unchecked by default).

  • If async mode is selected:

    • An Instructor Task is created to handle enrollment/unenrollment asynchronously using a Celery task.
    • A message is displayed in the UI confirming that the async process has started, and that an email will be sent once it finishes.
    • Task progress can be tracked in Instructor Dashboard > Pending Tasks.
    • Once complete, a CSV report with the enrollment/unenrollment results is generated and uploaded to Instructor Dashboard > Data Download.
    • An email notification is sent to the instructor with a direct link to download the report.
  • If async mode is not selected, the current synchronous behavior remains unchanged.

Screenshots

Before After
image image

Tooltip

image

Informative user message

image

Body email

image

CSV report

image

CSV content

image

Testing instructions

Using a Tutor environment:

  1. Mount edx-platform with the changes from this PR. I recommend using tutor local.

  2. Build the openedx image with tutor images build openedx.

  3. Create a course.

  4. Create some users (recommended: +100).

  5. Navigate to Instructor Dashboard > Membership > Batch Enrollment.

  6. Add the usernames or emails in the text area.

  7. Check the Process asynchronously checkbox.

  8. You should see an info message in the interface indicating that the process has started.

  9. When the process finishes:

    • A CSV report will be available in the Data Download tab of the Instructor Dashboard.
    • An email will be sent to the user who initiated the process.

Deadline

None

Other Information

I found a bug introduced in this PR. The user used in the create_manual_enrollment_audit method should be the request.user, not the identified_user.

https://github.com/openedx/edx-platform/blob/405282c17efcdb19f578ed553f728c9218a271a4/lms/djangoapps/instructor/views/api.py#L896-L898

I also fixed that bug in the current PR.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Aug 16, 2025
@openedx-webhooks
Copy link
Copy Markdown

openedx-webhooks commented Aug 16, 2025

Thanks for the pull request, @BryanttV!

This repository is currently maintained by @openedx/wg-maintenance-openedx-platform.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Aug 16, 2025
@BryanttV BryanttV force-pushed the bav/add-instructor-task-for-async-batch-enrollment branch 2 times, most recently from c8afbaf to be63ae3 Compare August 19, 2025 22:46
@BryanttV BryanttV marked this pull request as ready for review August 20, 2025 00:10
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Aug 21, 2025
@BryanttV BryanttV force-pushed the bav/add-instructor-task-for-async-batch-enrollment branch 3 times, most recently from ab47689 to b9f4211 Compare August 22, 2025 15:43
@efortish
Copy link
Copy Markdown
Contributor

efortish commented Sep 5, 2025

We can use something like this to create the users:

from django.contrib.auth.models import User
from common.djangoapps.student.models import UserProfile
from common.djangoapps.student.models import CourseEnrollment
from opaque_keys.edx.keys import CourseKey

course_key = CourseKey.from_string("course-v1:test+12+2025")
password = "test123"
amount = 100

for i in range(amount):
    username = f"user{i}"
    email = f"user{i}@example.com"
    user = User.objects.filter(username=username).first()

    if not user:
        user = User.objects.create_user(username=username, email=email, password=password)
        print(f"User created: {username}")
    else:
        print(f"User already exists: {username}")

    try:
        user_profile = user.profile
    except User.profile.RelatedObjectDoesNotExist:
        user_profile = UserProfile.objects.create(user=user, name=username)
        print(f"Profile created: {username}")

    if not CourseEnrollment.objects.filter(user=user, course_id=course_key).exists():
        CourseEnrollment.enroll(user, course_key)
        print(f"{username} enrolled successfully")
    else:
        print(f"{username} is already enrolled")
```

@openedx-webhooks openedx-webhooks added the core contributor PR author is a Core Contributor (who may or may not have write access to this repo). label Sep 5, 2025
@efortish efortish self-requested a review September 5, 2025 23:53
Copy link
Copy Markdown
Contributor

@efortish efortish left a comment

Choose a reason for hiding this comment

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

Hi @BryanttV

I tried the new feature and it is working as expected, thank you so much for your contribution.

Can we add a detail test suit for this new feature?

@mphilbrick211
Copy link
Copy Markdown

hi @BryanttV! Bumping this for you.

@BryanttV BryanttV force-pushed the bav/add-instructor-task-for-async-batch-enrollment branch from b9f4211 to d2fb230 Compare September 30, 2025 01:13
@BryanttV
Copy link
Copy Markdown
Contributor Author

Thanks for your review @efortish! I will be working on implementing the unit tests.
And thanks for the ping @mphilbrick211!

@mphilbrick211 mphilbrick211 moved this from Waiting on Author to In Eng Review in Contributions Oct 8, 2025
@BryanttV BryanttV marked this pull request as draft November 24, 2025 19:34
@BryanttV BryanttV force-pushed the bav/add-instructor-task-for-async-batch-enrollment branch 4 times, most recently from 192e8c5 to 3e4728a Compare November 26, 2025 16:20
@BryanttV BryanttV marked this pull request as ready for review November 26, 2025 17:39
@mphilbrick211
Copy link
Copy Markdown

@BryanttV @mariajgrimaldi hi there! is this still in progress?

@mphilbrick211
Copy link
Copy Markdown

@BryanttV @mariajgrimaldi hi there! is this still in progress?

Final ping on this one, @BryanttV!

@mphilbrick211 mphilbrick211 added the inactive PR author has been unresponsive for several months label Apr 6, 2026
@MaferMazu
Copy link
Copy Markdown
Contributor

@mphilbrick211, in my understanding, @BryanttV would continue with this PR.

@BryanttV, could you update the PR so it can receive a proper review? ✨

@BryanttV BryanttV force-pushed the bav/add-instructor-task-for-async-batch-enrollment branch from 279fbb5 to 8851b1e Compare May 8, 2026 18:30
@BryanttV BryanttV requested a review from MaferMazu May 8, 2026 23:15
@BryanttV
Copy link
Copy Markdown
Contributor Author

Hi @MaferMazu, thanks for the review! I've addressed your comments. Could you take another look?

@MaferMazu
Copy link
Copy Markdown
Contributor

@BryanttV thanks for addressing my comments.
✅ All looks good! I only have one comment left based on a Gemini suggestion ( #37216 (comment)), after solving that we can merge this. Thanks again.

@BryanttV BryanttV force-pushed the bav/add-instructor-task-for-async-batch-enrollment branch from 337d3dd to 479ff5c Compare May 12, 2026 20:52
Copy link
Copy Markdown
Contributor

@MaferMazu MaferMazu left a comment

Choose a reason for hiding this comment

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

@BryanttV thanks for addressing my comments! This looks good to me! After the tests pass, we are good to merge! Thanks for this change 🙌

@BryanttV BryanttV requested a review from MaferMazu May 12, 2026 20:59
@BryanttV
Copy link
Copy Markdown
Contributor Author

Hi @MaferMazu! The checks passed 💯 Can we proceed with the merge?

@MaferMazu MaferMazu merged commit 03920db into openedx:master May 13, 2026
42 checks passed
@openedx-webhooks openedx-webhooks removed the inactive PR author has been unresponsive for several months label May 13, 2026
@github-project-automation github-project-automation Bot moved this from In Eng Review to Done in Contributions May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants