@task()
def rerun_course(source_course_key_string, destination_course_key_string, user_id, fields=None):
 from edxval.api import copy_course_videos
 try:
  source_course_key = CourseKey.from_string(source_course_key_string)
  destination_course_key = CourseKey.from_string(destination_course_key_string)
  fields = (deserialize_fields(fields) if fields else None)
  store = modulestore()
  with store.default_store('split'):
   store.clone_course(source_course_key, destination_course_key, user_id, fields=fields)
  initialize_permissions(destination_course_key, User.objects.get(id=user_id))
  CourseRerunState.objects.succeeded(course_key=destination_course_key)
  copy_course_videos(source_course_key, destination_course_key)
  return 'succeeded'
 except DuplicateCourseError as exc:
  CourseRerunState.objects.failed(course_key=destination_course_key)
  logging.exception(u'Course Rerun Error')
  return 'duplicate course'
 except Exception as exc:
  CourseRerunState.objects.failed(course_key=destination_course_key)
  logging.exception(u'Course Rerun Error')
  try:
   modulestore().delete_course(destination_course_key, user_id)
  except ItemNotFoundError:
   pass
  return ('exception: ' + unicode(exc))

@ task ( ) def rerun_course ( source_course_key_string , destination_course_key_string , user_id , fields = None ) : from edxval . api import copy_course_videos try : source_course_key = CourseKey . from_string ( source_course_key_string ) destination_course_key = CourseKey . from_string ( destination_course_key_string ) fields = ( deserialize_fields ( fields ) if fields else None ) store = modulestore ( ) with store . default_store ( 'split' ) : store . clone_course ( source_course_key , destination_course_key , user_id , fields = fields ) initialize_permissions ( destination_course_key , User . objects . get ( id = user_id ) ) CourseRerunState . objects . succeeded ( course_key = destination_course_key ) copy_course_videos ( source_course_key , destination_course_key ) return 'succeeded' except DuplicateCourseError as exc : CourseRerunState . objects . failed ( course_key = destination_course_key ) logging . exception ( u'Course Rerun Error' ) return 'duplicate course' except Exception as exc : CourseRerunState . objects . failed ( course_key = destination_course_key ) logging . exception ( u'Course Rerun Error' ) try : modulestore ( ) . delete_course ( destination_course_key , user_id ) except ItemNotFoundError : pass return ( 'exception: ' + unicode ( exc ) )
reruns a course in a new celery task .