Verified Commit 0f03b28b authored by Peter Stanko's avatar Peter Stanko
Browse files

Ability to resend the submission to the worker by admin and to get the worker...

Ability to resend the submission to the worker by admin and to get the worker params in case of the pull model
parent 9948088e
Pipeline #26458 passed with stage
in 7 minutes and 39 seconds
......@@ -3,7 +3,6 @@ from storage import UploadedEntity
from portal import storage
from portal.async_celery import celery_app, submission_processor
from portal.database import SubmissionState
log = get_task_logger(__name__)
......
......@@ -912,6 +912,15 @@ class Submission(db.Model, EntityBase):
SubmissionState.READY: [SubmissionState.CREATED]
}
@property
def worker_parameters(self) -> dict:
params = {
**self.parameters,
'id': self.id,
'test_files_hash': self.project.config.test_files_commit_hash,
}
return params
@property
def log_name(self):
return f"{self.id} ({self.course.codename}/{self.project.codename} for " \
......
......@@ -19,6 +19,7 @@ def log_files_access(what, submission, client):
FILES.info(f"{what} for {submission.log_name} accessed by: {client.log_name}"
f" IP: {request_helpers.get_ip()}, UA: {flask.request.user_agent}")
@submissions_namespace.route('')
class SubmissionsResource(CustomResource):
@jwt_required
......@@ -245,6 +246,43 @@ class SubmissionResubmit(CustomResource):
return SCHEMAS.dump('submission', new_submission), 201
@submissions_namespace.route('/<string:sid>/resend')
@submissions_namespace.param('sid', 'Submission id')
@submissions_namespace.response(404, 'Submissions not found')
class SubmissionResebd(CustomResource):
@jwt_required
@access_log
# @submissions_namespace.response(201, 'New submission', model=submission_schema)
def post(self, sid: str):
submission = self.find.submission(sid)
# authorization
self.permissions.require.sysadmin()
service = self.rest.submissions(submission)
service.resend_submission()
log.info(f"[REST] Resend submission {submission.log_name} by "
f"{self.client.log_name}")
return SCHEMAS.dump('submission', submission), 200
@submissions_namespace.route('/<string:sid>/worker_params')
@submissions_namespace.param('sid', 'Submission id')
@submissions_namespace.response(404, 'Submissions not found')
class SubmissionWorkerParams(CustomResource):
@jwt_required
@access_log
# @submissions_namespace.response(201, 'New submission', model=submission_schema)
def get(self, sid: str):
submission = self.find.submission(sid)
# authorization
course = submission.project.course
perm_service = self.permissions(course=course)
perm_service.require.read_submission(submission)
log.debug(f"[REST] Worker params for submission {submission.log_name}"
f": {submission.worker_parameters}")
return submission.worker_parameters, 200
@submissions_namespace.route('/<string:sid>/cancel')
@submissions_namespace.param('sid', 'Submission id')
@submissions_namespace.response(404, 'Submissions not found')
......
......@@ -135,6 +135,12 @@ class SubmissionsService(GeneralService):
source_id=self.submission.id, target_id=new_submission.id)
return new_submission
def resend_submission(self):
""" Resends the submission to the worker
"""
log.info(f"[SUBMIT] Resending submission task for {self.submission.log_name}")
tasks.start_processing_submission.delay(self.submission.id)
def delete(self):
"""Deletes a submission
......
......@@ -73,10 +73,8 @@ class WorkerClient:
def execute_submission(self, submission):
log.info(f"[W-API] Executing in {self.worker_name}: {submission.log_name}")
parameters = submission.parameters
parameters['test_files_hash'] = submission.project.config.test_files_commit_hash
parameters['id'] = submission.id
result = self.make_request(f'/submissions/{submission.id}', method='post', json=parameters)
result = self.make_request(f'/submissions/{submission.id}', method='post',
json=submission.worker_parameters)
return result
def get_submission(self, submission):
......
......@@ -117,6 +117,17 @@ def test_read(client):
rest_tools.assert_submission_in(submissions, submission)
# missing tests for working with zip
def test_worker_params(client):
submission: Submission = Submission.query.first()
response = rest_tools.make_request(client, f'/submissions/{submission.id}/worker_params', )
assert_response(response, 200)
params = rest_tools.extract_data(response)
assert params['test_files_hash'] == submission.project.config.test_files_commit_hash
assert params['id'] == submission.id
def test_student_is_able_to_access_own_submission(client, rest_service, student_credentials):
student = rest_service.find.user('student1')
submission = student.submissions[0]
......
Supports Markdown
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