Commit 750f30b2 by Tyler Hallada

Pass event transaction id & type to recalculate

parent 735824e2
...@@ -3,10 +3,12 @@ from datetime import datetime ...@@ -3,10 +3,12 @@ from datetime import datetime
import pytz import pytz
from opaque_keys.edx.keys import CourseKey, UsageKey from opaque_keys.edx.keys import CourseKey, UsageKey
from track.event_transaction_utils import create_new_event_transaction_id, set_event_transaction_type
from util.date_utils import to_timestamp from util.date_utils import to_timestamp
from .constants import ScoreDatabaseTableEnum from .constants import ScoreDatabaseTableEnum
from .models import PersistentSubsectionGrade, PersistentSubsectionGradeOverride from .models import PersistentSubsectionGrade, PersistentSubsectionGradeOverride
from .signals.handlers import SUBSECTION_RESCORE_EVENT_TYPE
def _get_key(key_or_id, key_cls): def _get_key(key_or_id, key_cls):
...@@ -87,6 +89,8 @@ class GradesService(object): ...@@ -87,6 +89,8 @@ class GradesService(object):
# Recalculation will call PersistentSubsectionGrade.update_or_create_grade which will use the above override # Recalculation will call PersistentSubsectionGrade.update_or_create_grade which will use the above override
# to update the grade before writing to the table. # to update the grade before writing to the table.
event_transaction_id = create_new_event_transaction_id()
set_event_transaction_type(SUBSECTION_RESCORE_EVENT_TYPE)
recalculate_subsection_grade_v3.apply_async( recalculate_subsection_grade_v3.apply_async(
kwargs=dict( kwargs=dict(
user_id=user_id, user_id=user_id,
...@@ -94,6 +98,8 @@ class GradesService(object): ...@@ -94,6 +98,8 @@ class GradesService(object):
usage_id=unicode(usage_key), usage_id=unicode(usage_key),
only_if_higher=False, only_if_higher=False,
expected_modified=to_timestamp(override.modified), expected_modified=to_timestamp(override.modified),
event_transaction_id=unicode(event_transaction_id),
event_transaction_type=SUBSECTION_RESCORE_EVENT_TYPE,
score_db_table=ScoreDatabaseTableEnum.overrides score_db_table=ScoreDatabaseTableEnum.overrides
) )
) )
...@@ -115,6 +121,8 @@ class GradesService(object): ...@@ -115,6 +121,8 @@ class GradesService(object):
if override is not None: if override is not None:
override.delete() override.delete()
event_transaction_id = create_new_event_transaction_id()
set_event_transaction_type(SUBSECTION_RESCORE_EVENT_TYPE)
recalculate_subsection_grade_v3.apply_async( recalculate_subsection_grade_v3.apply_async(
kwargs=dict( kwargs=dict(
user_id=user_id, user_id=user_id,
...@@ -124,6 +132,8 @@ class GradesService(object): ...@@ -124,6 +132,8 @@ class GradesService(object):
# Not used when score_deleted=True: # Not used when score_deleted=True:
expected_modified=to_timestamp(datetime.now().replace(tzinfo=pytz.UTC)), expected_modified=to_timestamp(datetime.now().replace(tzinfo=pytz.UTC)),
score_deleted=True, score_deleted=True,
event_transaction_id=unicode(event_transaction_id),
event_transaction_type=SUBSECTION_RESCORE_EVENT_TYPE,
score_db_table=ScoreDatabaseTableEnum.overrides score_db_table=ScoreDatabaseTableEnum.overrides
) )
) )
...@@ -38,6 +38,7 @@ log = getLogger(__name__) ...@@ -38,6 +38,7 @@ log = getLogger(__name__)
# define values to be used in grading events # define values to be used in grading events
GRADES_RESCORE_EVENT_TYPE = 'edx.grades.problem.rescored' GRADES_RESCORE_EVENT_TYPE = 'edx.grades.problem.rescored'
PROBLEM_SUBMITTED_EVENT_TYPE = 'edx.grades.problem.submitted' PROBLEM_SUBMITTED_EVENT_TYPE = 'edx.grades.problem.submitted'
SUBSECTION_RESCORE_EVENT_TYPE = 'edx.grades.subsection.rescored'
@receiver(score_set) @receiver(score_set)
...@@ -292,3 +293,16 @@ def _emit_event(kwargs): ...@@ -292,3 +293,16 @@ def _emit_event(kwargs):
'event_transaction_type': unicode(root_type), 'event_transaction_type': unicode(root_type),
} }
) )
if root_type in [SUBSECTION_RESCORE_EVENT_TYPE]:
tracker.emit(
unicode(SUBSECTION_RESCORE_EVENT_TYPE),
{
'course_id': unicode(kwargs['course_id']),
'user_id': unicode(kwargs['user_id']),
'problem_id': unicode(kwargs['usage_id']),
'only_if_higher': kwargs.get('only_if_higher'),
'event_transaction_id': unicode(get_event_transaction_id()),
'event_transaction_type': unicode(root_type),
}
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment