Skip to content

Commit 4602624

Browse files
committed
feat: Add event emission for external grader scores
This commit adds the EXTERNAL_GRADER_SCORE_SUBMITTED event emission to the put_result endpoint in the XQueueViewSet. When a grader submits a result and the score is successfully saved, the system now emits an event with all the necessary information for the LMS to render the graded XBlock. Key changes: - Add queue_key field to ExternalGraderDetail model - Include queue_key in create_external_grader_detail method - Emit EXTERNAL_GRADER_SCORE_SUBMITTED event after successful score update - Implement robust false to propagate error and put submission in pending queue again - Add migration for the new queue_key field - Add openedx-events dependency This enables the event-driven approach for updating XBlocks with scoring data from the edx-submissions service, supporting the gradual migration away from HTTP-based XQueue callbacks.
1 parent e198d56 commit 4602624

17 files changed

Lines changed: 160 additions & 634 deletions
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Improving Transaction Handling in Get Submission
2+
================================================
3+
4+
Status
5+
------
6+
7+
**Provisional** *2025-03-19*
8+
9+
Context
10+
-------
11+
12+
We identified a concurrency issue in the submission processing flow. Multiple instances of the xqueue watcher were processing the same transaction simultaneously, causing duplicate handling of submissions. Additionally, submissions remained stuck in the "pulled" state indefinitely when errors or unexpected interruptions occurred during processing.
13+
14+
Decision
15+
--------
16+
17+
We introduced a robust locking mechanism at the database level to prevent concurrent processing of the same submission. Specifically, we employed database row-level locking (`select_for_update(nowait=True)`) on submissions to ensure only one xqueue watcher instance can process a transaction at a time. Additionally, we implemented a timeout-based fallback, marking submissions in the "pulled" state as available again if they exceed a defined timeout period (5 minutes).
18+
19+
Consequences
20+
------------
21+
22+
Positive
23+
~~~~~~~~
24+
25+
- Ensures data consistency by preventing duplicate transaction processing.
26+
- Implements automatic recovery for submissions stuck in the "pulled" state, improving overall system reliability.
27+
- Minimal impact on system performance due to efficient database-level locking.
28+
29+
Negative
30+
~~~~~~~~
31+
32+
- Slightly increased complexity in transaction handling logic.
33+
- Potential minor latency increase when contention occurs due to database locks.

requirements/base.txt

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,16 @@
11
#
2-
# This file is autogenerated by pip-compile with Python 3.12
2+
# This file is autogenerated by pip-compile with Python 3.11
33
# by the following command:
44
#
55
# make upgrade
66
#
77
asgiref==3.8.1
8-
# via django
98
django==4.2.21
10-
# via
11-
# -c /home/runner/work/edx-submissions/edx-submissions/requirements/common_constraints.txt
12-
# -r requirements/base.in
13-
# django-model-utils
14-
# djangorestframework
15-
# edx-django-release-util
16-
# jsonfield
179
django-model-utils==5.0.0
18-
# via -r requirements/base.in
1910
djangorestframework==3.16.0
20-
# via -r requirements/base.in
2111
edx-django-release-util==1.5.0
22-
# via -r requirements/base.in
2312
jsonfield==3.1.0
24-
# via -r requirements/base.in
2513
pytz==2025.2
26-
# via -r requirements/base.in
2714
pyyaml==6.0.2
28-
# via edx-django-release-util
2915
six==1.17.0
30-
# via edx-django-release-util
3116
sqlparse==0.5.3
32-
# via django

requirements/ci.txt

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,25 @@
11
#
2-
# This file is autogenerated by pip-compile with Python 3.12
2+
# This file is autogenerated by pip-compile with Python 3.11
33
# by the following command:
44
#
55
# make upgrade
66
#
77
cachetools==5.5.2
8-
# via
9-
# -r /home/runner/work/edx-submissions/edx-submissions/requirements/tox.txt
10-
# tox
118
certifi==2025.4.26
12-
# via requests
139
chardet==5.2.0
14-
# via
15-
# -r /home/runner/work/edx-submissions/edx-submissions/requirements/tox.txt
16-
# tox
1710
charset-normalizer==3.4.2
18-
# via requests
1911
colorama==0.4.6
20-
# via
21-
# -r /home/runner/work/edx-submissions/edx-submissions/requirements/tox.txt
22-
# tox
2312
coverage[toml]==7.8.0
24-
# via coveralls
2513
coveralls==4.0.1
26-
# via -r requirements/ci.in
2714
distlib==0.3.9
28-
# via
29-
# -r /home/runner/work/edx-submissions/edx-submissions/requirements/tox.txt
30-
# virtualenv
3115
docopt==0.6.2
32-
# via coveralls
3316
filelock==3.18.0
34-
# via
35-
# -r /home/runner/work/edx-submissions/edx-submissions/requirements/tox.txt
36-
# tox
37-
# virtualenv
3817
idna==3.10
39-
# via requests
4018
packaging==25.0
41-
# via
42-
# -r /home/runner/work/edx-submissions/edx-submissions/requirements/tox.txt
43-
# pyproject-api
44-
# tox
4519
platformdirs==4.3.8
46-
# via
47-
# -r /home/runner/work/edx-submissions/edx-submissions/requirements/tox.txt
48-
# tox
49-
# virtualenv
5020
pluggy==1.5.0
51-
# via
52-
# -r /home/runner/work/edx-submissions/edx-submissions/requirements/tox.txt
53-
# tox
5421
pyproject-api==1.9.1
55-
# via
56-
# -r /home/runner/work/edx-submissions/edx-submissions/requirements/tox.txt
57-
# tox
5822
requests==2.32.3
59-
# via coveralls
6023
tox==4.25.0
61-
# via -r /home/runner/work/edx-submissions/edx-submissions/requirements/tox.txt
6224
urllib3==2.2.3
63-
# via
64-
# -c /home/runner/work/edx-submissions/edx-submissions/requirements/common_constraints.txt
65-
# requests
6625
virtualenv==20.31.2
67-
# via
68-
# -r /home/runner/work/edx-submissions/edx-submissions/requirements/tox.txt
69-
# tox

requirements/common_constraints.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
# See BOM-2721 for more details.
44
# Below is the copied and edited version of common_constraints
55

6+
# This is a temporary solution to override the real common_constraints.txt
7+
# In edx-lint, until the pyjwt constraint in edx-lint has been removed.
8+
# See BOM-2721 for more details.
9+
# Below is the copied and edited version of common_constraints
10+
11+
# This is a temporary solution to override the real common_constraints.txt
12+
# In edx-lint, until the pyjwt constraint in edx-lint has been removed.
13+
# See BOM-2721 for more details.
14+
# Below is the copied and edited version of common_constraints
15+
616
# A central location for most common version constraints
717
# (across edx repos) for pip-installation.
818
#

0 commit comments

Comments
 (0)