Commit 37db65fa by Christina Roberts Committed by GitHub

Merge pull request #13131 from edx/christina/retry-celery

Retry on failures (database locking).
parents 829b7641 7efc7fe4
......@@ -15,8 +15,8 @@ from openedx.core.djangoapps.course_groups.cohorts import (
LOGGER = get_task_logger(__name__)
@task()
def sync_cohort_with_mode(course_id, user_id, verified_cohort_name, default_cohort_name):
@task(bind=True, default_retry_delay=60, max_retries=4)
def sync_cohort_with_mode(self, course_id, user_id, verified_cohort_name, default_cohort_name):
"""
If the learner's mode does not match their assigned cohort, move the learner into the correct cohort.
It is assumed that this task is only initiated for courses that are using the
......@@ -26,6 +26,7 @@ def sync_cohort_with_mode(course_id, user_id, verified_cohort_name, default_coho
"""
course_key = CourseKey.from_string(course_id)
user = User.objects.get(id=user_id)
try:
enrollment = CourseEnrollment.get_enrollment(user, course_key)
# Note that this will enroll the user in the default cohort on initial enrollment.
# That's good because it will force creation of the default cohort if necessary.
......@@ -51,3 +52,9 @@ def sync_cohort_with_mode(course_id, user_id, verified_cohort_name, default_coho
"The user is already in cohort '%s'.",
user.username, course_id, enrollment.mode, current_cohort.name
)
except Exception as exc:
LOGGER.warning(
"SYNC_COHORT_WITH_MODE_RETRY: Exception encountered for course '%s' and user '%s': %s",
course_id, user.username, unicode(exc)
)
raise self.retry(exc=exc)
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