Skip to content

fix: run Course Optimizer extended-analysis export/upload as a background task - #466

Open
nsprenkle wants to merge 1 commit into
release-ulmofrom
nsprenkle/course-optimizer-async-analysis
Open

fix: run Course Optimizer extended-analysis export/upload as a background task#466
nsprenkle wants to merge 1 commit into
release-ulmofrom
nsprenkle/course-optimizer-async-analysis

Conversation

@nsprenkle

@nsprenkle nsprenkle commented Sep 9, 2026

Copy link
Copy Markdown
Member

Description

Follow-up to #426. A reviewer flagged that CourseAnalysisReportView.post was exporting and compressing the course, then uploading it to xpert-ai-workflows, synchronously inside the Studio request thread -- large courses could tie up a web worker long enough to hit a proxy/gateway timeout, and there was no way to bound the export/compress step at all (only the network POST itself had a timeout).

This moves that work into a new Celery task, submit_course_analysis_report, mirroring the existing export_olx / LinkCheckView pattern already used elsewhere in this module for exactly this shape of problem (expensive course-scoped work + client polling for status). CourseAnalysisReportView.post now just enqueues the task and returns 202 {"status": "pending"} immediately.

CourseAnalysisReportStatusView is unaffected by this change -- it already polls xpert-ai-workflows by course id (GET /courses/{course_id}/runs/latest), not by run id, so no Studio-side run-tracking state needed to be added to support the async POST; the frontend's existing polling already treats "no run yet" as still-pending.

Supporting information

Companion PR (same change on the frontend side, though no functional changes were needed beyond removing an unused runId field from the POST response): edx/frontend-app-authoring#114

Testing instructions

  1. Enable the contentstore.enable_course_optimizer_extended_checks waffle flag for a test course.
  2. Trigger a POST to /api/contentstore/v1/course_optimizer/analysis/{course_id} (e.g. via the frontend's "Start analysis" button) -- it should return 202 immediately rather than waiting for the export/upload to complete.
  3. Confirm a Celery worker log shows submit_course_analysis_report running and POSTing to xpert-ai-workflows.
  4. pytest cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_optimizer.py cms/djangoapps/contentstore/tests/test_tasks.py should pass.

…ound task

CourseAnalysisReportView.post previously exported and compressed the
course, then uploaded it to xpert-ai-workflows, synchronously inside the
request thread -- large courses could tie up a Studio web worker long
enough to hit a proxy/gateway timeout. Moves that work into a new Celery
task (submit_course_analysis_report, mirroring export_olx/LinkCheckView's
existing pattern in this module) so the view returns 202 immediately.

CourseAnalysisReportStatusView is unaffected -- it already polls
xpert-ai-workflows by course id, not run id, so no run-tracking state
needed to be added on the Studio side to support this.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.

1 participant