Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2209: Add a feature to re-reun a submission by challenge host using UI #2340

Merged
merged 20 commits into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/jobs/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
views.get_remaining_submissions,
name="get_remaining_submissions",
),
url(
r'^re_run_submission/(?P<submission_id>[0-9]+)$',
RishabhJain2018 marked this conversation as resolved.
Show resolved Hide resolved
views.re_run_submission, name='re_run_submission'
),
url(
r"^challenge_phase_split/(?P<challenge_phase_split_id>[0-9]+)/leaderboard/$",
views.leaderboard,
Expand Down
66 changes: 66 additions & 0 deletions apps/jobs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import datetime
import json
import logging
import time

from rest_framework import permissions, status
from rest_framework.decorators import (
Expand Down Expand Up @@ -933,6 +934,71 @@ def update_submission(request, challenge_pk):
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


@api_view(['POST', ])
@throttle_classes([UserRateThrottle, ])
@permission_classes((permissions.IsAuthenticated, HasVerifiedEmail))
@authentication_classes((ExpiringTokenAuthentication,))
def re_run_submission(request, submission_id):
RishabhJain2018 marked this conversation as resolved.
Show resolved Hide resolved
"""
API endpoint to re-run a submission.
Only challenge host has access to this endpoint.
"""
try:
submission = Submission.objects.get(id=submission_id)
RishabhJain2018 marked this conversation as resolved.
Show resolved Hide resolved
logger.info('Submission found with submission number {}'
RishabhJain2018 marked this conversation as resolved.
Show resolved Hide resolved
.format(submission_id))
except Submission.DoesNotExist:
response_data = {'error': 'Submission with submission number {} does not exist'.format(submission_id)}
RishabhJain2018 marked this conversation as resolved.
Show resolved Hide resolved
return Response(response_data, status=status.HTTP_404_NOT_FOUND)

# check if the challenge phase exists or not
try:
challenge_phase = submission.challenge_phase
RishabhJain2018 marked this conversation as resolved.
Show resolved Hide resolved
challenge_phase_id = challenge_phase.id
except Exception as e:
response_data = {'error': 'Challenge Phase does not exist'}
return Response(response_data, status=status.HTTP_400_BAD_REQUEST)

# check if the challenge exists or not
try:
challenge = challenge_phase.challenge
RishabhJain2018 marked this conversation as resolved.
Show resolved Hide resolved
challenge_id = challenge.id
except Exception as e:
response_data = {'error': 'Challenge does not exist'}
return Response(response_data, status=status.HTTP_400_BAD_REQUEST)

if not is_user_a_host_of_challenge(request.user, challenge_id):
response_data = {
"error": "You are not allowed to re-run the challenge submission"
RishabhJain2018 marked this conversation as resolved.
Show resolved Hide resolved
}
return Response(response_data, status=status.HTTP_403_FORBIDDEN)

if not challenge.is_active:
response_data = {'error': 'Challenge is not active'}
RishabhJain2018 marked this conversation as resolved.
Show resolved Hide resolved
return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE)

# check if challenge phase is active
if not challenge_phase.is_active:
RishabhJain2018 marked this conversation as resolved.
Show resolved Hide resolved
response_data = {
'error': 'Sorry, cannot accept submissions since challenge phase is not active'}
return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE)
try:
RishabhJain2018 marked this conversation as resolved.
Show resolved Hide resolved
publish_submission_message(challenge_id, challenge_phase_id, submission.id)
time.sleep(1)
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved
submission = Submission.objects.get(id=submission_id)
RishabhJain2018 marked this conversation as resolved.
Show resolved Hide resolved
response_data = {
RishabhJain2018 marked this conversation as resolved.
Show resolved Hide resolved
'submission_status': submission.status,
'submission_execution_time': submission.execution_time,
'submission_number': submission.submission_number,
RishabhJain2018 marked this conversation as resolved.
Show resolved Hide resolved
'success': 'Submission result has been successfully updated'
RishabhJain2018 marked this conversation as resolved.
Show resolved Hide resolved
}
return Response(response_data, status=status.HTTP_200_OK)
except Exception as e:
logger.info('Error occured while sending to queue: {}'.format(str(e)))
response_data = {'error': 'Error occured while sending to queue'}
return Response(response_data, status=status.HTTP_400_BAD_REQUEST)


@api_view(["GET"])
@throttle_classes([UserRateThrottle])
@permission_classes((permissions.IsAuthenticated, HasVerifiedEmail))
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/css/modules/challenge.scss
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,28 @@ md-select.md-default-theme .md-select-value span:first-child:after, md-select .m
color: #252833;
}

@-webkit-keyframes spin {
from { -webkit-transform: rotate(0deg); }
to { -webkit-transform: rotate(360deg); }
}

@keyframes spin {
from {transform:rotate(0deg);}
to {transform:rotate(360deg);}
}


.spin {
-webkit-animation: spin 1s linear infinite;
animation: spin 1s linear infinite;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}

.progress-indicator {
width: 14px;
}

.btn-switch {
position: relative;
display: block;
Expand Down
27 changes: 27 additions & 0 deletions frontend/src/js/controllers/challengeCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,33 @@

utilities.sendRequest(parameters);
};

vm.reRunSubmission = function(submissionObject) {
submissionObject.classList = ['spin', 'progress-indicator'];
parameters.url = 'jobs/re_run_submission/' + submissionObject.id;
parameters.method = 'POST';
var formData = new FormData();
parameters.data = formData;

parameters.token = userKey;
parameters.callback = {
onSuccess: function(response) {
$rootScope.notify("success", "Your submission has been re-run succesfully!");
submissionObject.status = response.data.submission_status;
submissionObject.execution_time = response.data.submission_execution_time;
submissionObject.submission_number = response.data.submission_number;
submissionObject.classList = [''];
},
onError: function(response) {
var status = response.status;
var error = response.data;
$rootScope.notify("error", error);
submissionObject.classList = [''];
}
};
utilities.sendRequest(parameters);
};

vm.refreshLeaderboard = function() {
vm.startLoader("Loading Leaderboard Items");
vm.leaderboard = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<th data-field="file">Stderr File</th>
<th data-field="file">Result File</th>
<th data-field="file">Metadata File</th>
<th data-field="button">Re-run Submissions</th>
</thead>
<tbody>
<tr ng-repeat="key in challenge.submissionResult.results" class="result-val">
Expand Down Expand Up @@ -99,6 +100,7 @@
<label for="isPublic{{ key.id }}"></label>
<span ng-if="key.status !== 'finished'" class="center"> N/A </span>
</td>
<td><center><a ng-class="key.classList" class="fa fa-refresh pointer" ng-click="challenge.reRunSubmission(key)"></a></center></td>
</tr>
</tbody>
</table>
Expand Down