Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
7c1913b7
Commit
7c1913b7
authored
Oct 20, 2016
by
Eric Fischer
Committed by
GitHub
Oct 20, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13765 from edx/efischer/grades_task_retry
Recalculate Subsection Grade task retry logic
parents
ac48c2e4
529889f3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
10 deletions
+32
-10
lms/djangoapps/grades/tasks.py
+14
-10
lms/djangoapps/grades/tests/test_tasks.py
+18
-0
No files found.
lms/djangoapps/grades/tasks.py
View file @
7c1913b7
...
@@ -5,6 +5,7 @@ This module contains tasks for asynchronous execution of grade updates.
...
@@ -5,6 +5,7 @@ This module contains tasks for asynchronous execution of grade updates.
from
celery
import
task
from
celery
import
task
from
django.conf
import
settings
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.db.utils
import
IntegrityError
from
lms.djangoapps.course_blocks.api
import
get_course_blocks
from
lms.djangoapps.course_blocks.api
import
get_course_blocks
from
lms.djangoapps.courseware.courses
import
get_course_by_id
from
lms.djangoapps.courseware.courses
import
get_course_by_id
...
@@ -17,7 +18,7 @@ from .transformer import GradesTransformer
...
@@ -17,7 +18,7 @@ from .transformer import GradesTransformer
from
.new.subsection_grade
import
SubsectionGradeFactory
from
.new.subsection_grade
import
SubsectionGradeFactory
@task
(
routing_key
=
settings
.
RECALCULATE_GRADES_ROUTING_KEY
)
@task
(
default_retry_delay
=
30
,
routing_key
=
settings
.
RECALCULATE_GRADES_ROUTING_KEY
)
def
recalculate_subsection_grade
(
user_id
,
course_id
,
usage_id
):
def
recalculate_subsection_grade
(
user_id
,
course_id
,
usage_id
):
"""
"""
Updates a saved subsection grade.
Updates a saved subsection grade.
...
@@ -43,12 +44,15 @@ def recalculate_subsection_grade(user_id, course_id, usage_id):
...
@@ -43,12 +44,15 @@ def recalculate_subsection_grade(user_id, course_id, usage_id):
set
()
set
()
)
)
for
subsection_usage_key
in
subsections_to_update
:
try
:
transformed_subsection_structure
=
get_course_blocks
(
for
subsection_usage_key
in
subsections_to_update
:
student
,
transformed_subsection_structure
=
get_course_blocks
(
subsection_usage_key
,
student
,
collected_block_structure
=
collected_block_structure
,
subsection_usage_key
,
)
collected_block_structure
=
collected_block_structure
,
subsection_grade_factory
.
update
(
)
transformed_subsection_structure
[
subsection_usage_key
],
transformed_subsection_structure
subsection_grade_factory
.
update
(
)
transformed_subsection_structure
[
subsection_usage_key
],
transformed_subsection_structure
)
except
IntegrityError
as
exc
:
raise
recalculate_subsection_grade
.
retry
(
args
=
[
user_id
,
course_id
,
usage_id
],
exc
=
exc
)
lms/djangoapps/grades/tests/test_tasks.py
View file @
7c1913b7
...
@@ -4,6 +4,7 @@ Tests for the functionality and infrastructure of grades tasks.
...
@@ -4,6 +4,7 @@ Tests for the functionality and infrastructure of grades tasks.
import
ddt
import
ddt
from
django.conf
import
settings
from
django.conf
import
settings
from
django.db.utils
import
IntegrityError
from
mock
import
patch
from
mock
import
patch
from
unittest
import
skip
from
unittest
import
skip
...
@@ -154,3 +155,20 @@ class RecalculateSubsectionGradeTest(ModuleStoreTestCase):
...
@@ -154,3 +155,20 @@ class RecalculateSubsectionGradeTest(ModuleStoreTestCase):
self
.
score_changed_kwargs
[
'usage_id'
],
self
.
score_changed_kwargs
[
'usage_id'
],
)
)
)
)
@patch
(
'lms.djangoapps.grades.tasks.recalculate_subsection_grade.retry'
)
@patch
(
'lms.djangoapps.grades.new.subsection_grade.SubsectionGradeFactory.update'
)
def
test_retry_on_integrity_error
(
self
,
mock_update
,
mock_retry
):
"""
Ensures that tasks will be retried if IntegrityErrors are encountered.
"""
self
.
set_up_course
()
mock_update
.
side_effect
=
IntegrityError
(
"WHAMMY"
)
recalculate_subsection_grade
.
apply
(
args
=
(
self
.
score_changed_kwargs
[
'user_id'
],
self
.
score_changed_kwargs
[
'course_id'
],
self
.
score_changed_kwargs
[
'usage_id'
],
)
)
self
.
assertTrue
(
mock_retry
.
called
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment