From ee32af19479b2290f435b01bc0888f2a7ed7b8ba Mon Sep 17 00:00:00 2001 From: John McCann Cunniff Jr Date: Mon, 19 Sep 2022 19:33:57 -0400 Subject: [PATCH] ADD endpoint for manually retriggering autograde #394 --- api/anubis/rpc/enqueue.py | 6 ++++++ api/anubis/views/admin/autograde.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/api/anubis/rpc/enqueue.py b/api/anubis/rpc/enqueue.py index 7364448d9..0f867f9ed 100644 --- a/api/anubis/rpc/enqueue.py +++ b/api/anubis/rpc/enqueue.py @@ -18,6 +18,7 @@ from anubis.k8s.theia import reap_theia_session_by_id, reap_stale_theia_sessions from anubis.lms.assignments import make_shared_assignment from anubis.lms.questions import assign_missing_questions +from anubis.lms.autograde import bulk_autograde from anubis.utils.data import with_context from anubis.utils.testing.seed import seed @@ -105,3 +106,8 @@ def enqueue_create_assignment_github_repo(*args): def enqueue_reap_pvc_user(*args): """Enqueue reap pvc for user""" rpc_enqueue(reap_user_pvc, queue='default', args=args) + + +def enqueue_bulk_autograde(*args): + """Enqueue bulk autograde of assignment""" + rpc_enqueue(bulk_autograde, queue="regrade", args=args) diff --git a/api/anubis/views/admin/autograde.py b/api/anubis/views/admin/autograde.py index 2122115ed..4863b68f1 100644 --- a/api/anubis/views/admin/autograde.py +++ b/api/anubis/views/admin/autograde.py @@ -15,6 +15,7 @@ get_assignment_history, get_assignment_sundial, ) +from anubis.rpc.enqueue import enqueue_bulk_autograde autograde_ = Blueprint("admin-autograde", __name__, url_prefix="/admin/autograde") @@ -48,6 +49,33 @@ def admin_autograde_cache_reset(assignment_id: str): return success_response({"message": "success"}) +@autograde_.get("/run/") +@require_admin() +@json_response +def admin_autograde_run_assignment_id(assignment_id: str): + """ + + :param assignment_id: + :return: + """ + + # Pull the assignment object + assignment = Assignment.query.filter(Assignment.id == assignment_id).first() + + # Verify that we got an assignment + req_assert(assignment is not None, message="assignment does not exist") + + # Verify that the current course context, and the assignment course match + assert_course_context(assignment) + + # Enqueue regrade to be run in rpc worker + enqueue_bulk_autograde(assignment.id) + + return success_response({ + 'status': 'Regrade of assignment has been enqueued', + }) + + @autograde_.route("/assignment/") @require_admin() @json_response