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: Submission re-run functionality. #2228

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
5 changes: 5 additions & 0 deletions apps/jobs/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
views.get_remaining_submissions,
name="get_remaining_submissions",
),
url(
r'^challenge/(?P<challenge_id>[0-9]+)/'
RishabhJain2018 marked this conversation as resolved.
Show resolved Hide resolved
r'challenge_phase/(?P<challenge_phase_id>[0-9]+)/re_run_submission/(?P<submission_number>[0-9]+)$',
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
57 changes: 57 additions & 0 deletions apps/jobs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,63 @@ 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, challenge_id, challenge_phase_id, submission_number):
"""
API endpoint to re-run a submission.
Only challenge host has access to this endpoint.
"""
# check if the challenge exists or not
try:
challenge = Challenge.objects.get(pk=challenge_id)
except Challenge.DoesNotExist:
response_data = {'error': 'Challenge does not exist'}
return Response(response_data, status=status.HTTP_400_BAD_REQUEST)

# check if the challenge phase exists or not
try:
challenge_phase = ChallengePhase.objects.get(
pk=challenge_phase_id, challenge=challenge)
except ChallengePhase.DoesNotExist:
response_data = {'error': 'Challenge Phase does not exist'}
return Response(response_data, status=status.HTTP_400_BAD_REQUEST)

try:
submission = Submission.objects.get(submission_number=submission_number)
logger.info('Submission found with challenge ID {}, submission number {}'
.format(challenge_id, submission_number))
except Submission.DoesNotExist:
response_data = {'error': 'Submission with submission number {} does not exist'.format(submission_number)}
return Response(response_data, status=status.HTTP_404_NOT_FOUND)

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"
}
return Response(response_data, status=status.HTTP_403_FORBIDDEN)

if not challenge.is_active:
response_data = {'error': 'Challenge is not active'}
return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE)

# check if challenge phase is active
if not challenge_phase.is_active:
response_data = {
'error': 'Sorry, cannot accept submissions since challenge phase is not active'}
return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE)
try:
publish_submission_message(challenge_id, challenge_phase_id, submission.id)
response_data = {'success': 'Submission result has been successfully updated'}
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
24 changes: 24 additions & 0 deletions frontend/src/js/controllers/challengeCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,30 @@

utilities.sendRequest(parameters);
};

vm.rerunSubmission = function(submission_number) {
parameters.url = 'jobs/challenge/' + vm.challengeId +'/challenge_phase/' + vm.phaseId + '/re_run_submission/' + submission_number;
parameters.method = 'POST';
var formData = new FormData();
parameters.data = formData;

parameters.token = userKey;
parameters.callback = {
onSuccess: function() {
$rootScope.notify("success", "Your submission has been re-run succesfully!");
vm.stopLoader();
},
onError: function(response) {
var status = response.status;
var error = response.data;
$rootScope.notify("error", error);
vm.stopLoader();
}
};
vm.startLoader("Loading Submissions");
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,8 @@
<label for="isPublic{{ key.id }}"></label>
<span ng-if="key.status !== 'finished'" class="center"> N/A </span>
</td>

<td><button class="waves-effect waves-dark btn ev-btn-dark w-300 fs-14 " type="button" ng-click="challenge.rerunSubmission(key.submission_number)">Re-run submission</button></td>
</tr>
</tbody>
</table>
Expand Down