Pass event transaction id & type to recalculate
This commit is contained in:
@@ -3,10 +3,12 @@ from datetime import datetime
|
||||
import pytz
|
||||
|
||||
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 .constants import ScoreDatabaseTableEnum
|
||||
from .models import PersistentSubsectionGrade, PersistentSubsectionGradeOverride
|
||||
from .signals.handlers import SUBSECTION_RESCORE_EVENT_TYPE
|
||||
|
||||
|
||||
def _get_key(key_or_id, key_cls):
|
||||
@@ -87,6 +89,8 @@ class GradesService(object):
|
||||
|
||||
# Recalculation will call PersistentSubsectionGrade.update_or_create_grade which will use the above override
|
||||
# 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(
|
||||
kwargs=dict(
|
||||
user_id=user_id,
|
||||
@@ -94,6 +98,8 @@ class GradesService(object):
|
||||
usage_id=unicode(usage_key),
|
||||
only_if_higher=False,
|
||||
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
|
||||
)
|
||||
)
|
||||
@@ -115,6 +121,8 @@ class GradesService(object):
|
||||
if override is not None:
|
||||
override.delete()
|
||||
|
||||
event_transaction_id = create_new_event_transaction_id()
|
||||
set_event_transaction_type(SUBSECTION_RESCORE_EVENT_TYPE)
|
||||
recalculate_subsection_grade_v3.apply_async(
|
||||
kwargs=dict(
|
||||
user_id=user_id,
|
||||
@@ -124,6 +132,8 @@ class GradesService(object):
|
||||
# Not used when score_deleted=True:
|
||||
expected_modified=to_timestamp(datetime.now().replace(tzinfo=pytz.UTC)),
|
||||
score_deleted=True,
|
||||
event_transaction_id=unicode(event_transaction_id),
|
||||
event_transaction_type=SUBSECTION_RESCORE_EVENT_TYPE,
|
||||
score_db_table=ScoreDatabaseTableEnum.overrides
|
||||
)
|
||||
)
|
||||
|
||||
@@ -38,6 +38,7 @@ log = getLogger(__name__)
|
||||
# define values to be used in grading events
|
||||
GRADES_RESCORE_EVENT_TYPE = 'edx.grades.problem.rescored'
|
||||
PROBLEM_SUBMITTED_EVENT_TYPE = 'edx.grades.problem.submitted'
|
||||
SUBSECTION_RESCORE_EVENT_TYPE = 'edx.grades.subsection.rescored'
|
||||
|
||||
|
||||
@receiver(score_set)
|
||||
@@ -292,3 +293,16 @@ def _emit_event(kwargs):
|
||||
'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),
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user