def _acceptSubmission(request, course, exercise, post_url, sdir): ''' Queues the submission for grading. ''' uids = get_uid(request) attempt = int(request.GET.get("ordinal_number", 1)) if "submission_url" in request.GET: surl = request.GET["submission_url"] surl_missing = False else: LOGGER.warning("submission_url missing from a request") surl = request.build_absolute_uri(reverse('test-result')) surl_missing = True _acceptSubmission.counter += 1 # Order container for grading. c = _requireContainer(exercise) course_extra = { "key": course["key"], "name": course["name"], } exercise_extra = { "key": exercise["key"], "title": exercise.get("title", None), "resources": c.get("resources", {}), # Unofficial param, implemented differently later "require_constant_environment": c.get("require_constant_environment", False) # Unofficial param, implemented differently later } if exercise.get("personalized", False): exercise_extra["personalized_exercise"] \ = select_generated_exercise_instance(course, exercise, uids, attempt) sid = os.path.basename(sdir) write_submission_meta( sid, { "url": surl, "dir": sdir, "course_key": course["key"], "exercise_key": exercise["key"], "lang": translation.get_language(), }) r = invoke([ settings.CONTAINER_SCRIPT, sid, request.scheme + "://" + request.get_host(), c["image"], os.path.join(DIR, course["key"], c["mount"]), sdir, c["cmd"], json.dumps(course_extra), json.dumps(exercise_extra), ]) LOGGER.debug("Container order exit=%d out=%s err=%s", r["code"], r["out"], r["err"]) qlen = 1 return render_template(request, course, exercise, post_url, "access/async_accepted.html", { "accepted": True, "wait": True, "missing_url": surl_missing, "queue": qlen })
def _acceptSubmission(request, course, exercise, post_url, sdir): ''' Queues the submission for grading. ''' uids = get_uid(request) attempt = int(request.GET.get("ordinal_number", 1)) container_flag = settings.CONTAINER_MODE and "container" in exercise # Backup synchronous grading. if not container_flag and not settings.CELERY_BROKER: LOGGER.warning("No queue configured") from grader.runactions import runactions r = runactions(course, exercise, sdir, uids, attempt) html = template_to_str(course, exercise, "", r["template"], r["result"]) return render_template( request, course, exercise, post_url, "access/async_accepted.html", { "synchronous": True, "accepted": True, "max_points": r["result"].get("max_points", 1), "points": r["result"].get("points", 0), "feedback": html, }) if "submission_url" in request.GET: surl = request.GET["submission_url"] surl_missing = False else: LOGGER.warning("submission_url missing from a request") surl = request.build_absolute_uri(reverse('test-result')) surl_missing = True _acceptSubmission.counter += 1 # Order container for grading. if container_flag: c = _requireContainer(exercise) course_extra = { "key": course["key"], "name": course["name"], } exercise_extra = { "key": exercise["key"], "title": exercise.get("title", None), } if exercise.get("personalized", False): exercise_extra["personalized_exercise"] \ = select_generated_exercise_instance(course, exercise, uids, attempt) if settings.ENABLE_PERSONAL_DIRECTORIES: exercise_extra["personal_directory"] \ = user_personal_directory_path(course, exercise, uids) sid = os.path.basename(sdir) write_submission_meta(sid, { "url": surl, "dir": sdir, }) r = invoke([ settings.CONTAINER_SCRIPT, sid, request.scheme + "://" + request.get_host(), c["image"], os.path.join(DIR, course["key"], c["mount"]), sdir, c["cmd"], json.dumps(course_extra), json.dumps(exercise_extra), ]) LOGGER.debug("Container order exit=%d out=%s err=%s", r["code"], r["out"], r["err"]) qlen = 1 # Queue in celery & rabbitmq for chroot sandbox actions. else: tasks.grade.delay(course["key"], exercise["key"], translation.get_language(), surl, sdir, uids, attempt) qlen = queue_length() LOGGER.debug("Submission of %s/%s, queue counter %d, queue length %d", course["key"], exercise["key"], _acceptSubmission.counter, qlen) if qlen >= settings.QUEUE_ALERT_LENGTH: LOGGER.error("Queue alert, length: %d", qlen) return render_template(request, course, exercise, post_url, "access/async_accepted.html", { "accepted": True, "wait": True, "missing_url": surl_missing, "queue": qlen })
def _acceptSubmission(request, course, exercise, post_url, sdir): ''' Queues the submission for grading. ''' uids = get_uid(request) attempt = int(request.GET.get("ordinal_number", 1)) container_flag = settings.CONTAINER_MODE and "container" in exercise # Backup synchronous grading. if not container_flag and not settings.CELERY_BROKER: LOGGER.warning("No queue configured") from grader.runactions import runactions r = runactions(course, exercise, sdir, uids, attempt) html = template_to_str(course, exercise, "", r["template"], r["result"]) return render_template(request, course, exercise, post_url, "access/async_accepted.html", { "synchronous": True, "accepted": True, "max_points": r["result"].get("max_points", 1), "points": r["result"].get("points", 0), "feedback": html, }) if "submission_url" in request.GET: surl = request.GET["submission_url"] surl_missing = False else: LOGGER.warning("submission_url missing from a request") surl = request.build_absolute_uri(reverse('test-result')) surl_missing = True _acceptSubmission.counter += 1 # Order container for grading. if container_flag: c = _requireContainer(exercise) course_extra = { "key": course["key"], "name": course["name"], } exercise_extra = { "key": exercise["key"], "title": exercise.get("title", None), "resources": c.get("resources", {}), # Unofficial param, implemented differently later "require_constant_environment": c.get("require_constant_environment", False) # Unofficial param, implemented differently later } if exercise.get("personalized", False): exercise_extra["personalized_exercise"] \ = select_generated_exercise_instance(course, exercise, uids, attempt) if settings.ENABLE_PERSONAL_DIRECTORIES: exercise_extra["personal_directory"] \ = user_personal_directory_path(course, exercise, uids) sid = os.path.basename(sdir) write_submission_meta(sid, { "url": surl, "dir": sdir, "course_key": course["key"], "exercise_key": exercise["key"], "lang": translation.get_language(), }) r = invoke([ settings.CONTAINER_SCRIPT, sid, request.scheme + "://" + request.get_host(), c["image"], os.path.join(DIR, course["key"], c["mount"]), sdir, c["cmd"], json.dumps(course_extra), json.dumps(exercise_extra), ]) LOGGER.debug("Container order exit=%d out=%s err=%s", r["code"], r["out"], r["err"]) qlen = 1 # Queue in celery & rabbitmq for chroot sandbox actions. else: tasks.grade.delay(course["key"], exercise["key"], translation.get_language(), surl, sdir, uids, attempt) qlen = queue_length() LOGGER.debug("Submission of %s/%s, queue counter %d, queue length %d", course["key"], exercise["key"], _acceptSubmission.counter, qlen) if qlen >= settings.QUEUE_ALERT_LENGTH: LOGGER.error("Queue alert, length: %d", qlen) return render_template(request, course, exercise, post_url, "access/async_accepted.html", { "accepted": True, "wait": True, "missing_url": surl_missing, "queue": qlen })