Commit fcd11d93 by Julian Arni

Handle nginx 499s and double requests

parent 8a8bcf28
...@@ -89,16 +89,20 @@ def import_course(request, org, course, name): ...@@ -89,16 +89,20 @@ def import_course(request, org, course, name):
# Check to make sure we haven't missed a chunk # Check to make sure we haven't missed a chunk
# This shouldn't happen, even if different instances are handling # This shouldn't happen, even if different instances are handling
# the same session, but it's always better to catch errors earlier. # the same session, but it's always better to catch errors earlier.
if size != int(content_range['start']): if size < int(content_range['start']):
log.warning( log.warning(
"Reported range %s does not match size downloaded so far %s", "Reported range %s does not match size downloaded so far %s",
size, content_range['start'],
content_range['start'] size
) )
return JsonResponse( return JsonResponse(
{'ErrMsg': 'File upload corrupted. Please try again'}, {'ErrMsg': 'File upload corrupted. Please try again'},
status=409 status=409
) )
# The last request sometimes comes twice. This happens because
# nginx sends a 499 error code when the response takes too long.
elif size > int(content_range['stop']) and size == int(content_range['end']):
return JsonResponse({'ImportStatus': 1})
with open(temp_filepath, mode) as temp_file: with open(temp_filepath, mode) as temp_file:
for chunk in request.FILES['course-data'].chunks(): for chunk in request.FILES['course-data'].chunks():
......
...@@ -57,6 +57,11 @@ body.course.import { ...@@ -57,6 +57,11 @@ body.course.import {
color: $error-red; color: $error-red;
} }
.status-block {
display: none;
font-size: 13px;
}
.choose-file-button { .choose-file-button {
@include blue-button; @include blue-button;
padding: 10px 50px 11px; padding: 10px 50px 11px;
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
<input type="file" name="course-data" class="file-input" > <input type="file" name="course-data" class="file-input" >
<input type="submit" value="${_('Replace my course with the one above')}" class="submit-button" > <input type="submit" value="${_('Replace my course with the one above')}" class="submit-button" >
<input type="hidden" name="csrfmiddlewaretoken" value="${csrf_token}"> <input type="hidden" name="csrfmiddlewaretoken" value="${csrf_token}">
<p class="status-block">Unpacking...</p>
<div class="progress-bar"> <div class="progress-bar">
<div class="progress-fill"></div> <div class="progress-fill"></div>
<div class="percent">0%</div> <div class="percent">0%</div>
...@@ -55,6 +56,7 @@ var bar = $('.progress-bar'); ...@@ -55,6 +56,7 @@ var bar = $('.progress-bar');
var fill = $('.progress-fill'); var fill = $('.progress-fill');
var percent = $('.percent'); var percent = $('.percent');
var status = $('#status'); var status = $('#status');
var statusBlock = $('.status-block');
var submitBtn = $('.submit-button'); var submitBtn = $('.submit-button');
...@@ -79,6 +81,11 @@ $('#fileupload').fileupload({ ...@@ -79,6 +81,11 @@ $('#fileupload').fileupload({
alert('${_("Your import has failed.")}\n\n' + JSON.parse(result.responseText)["ErrMsg"]); alert('${_("Your import has failed.")}\n\n' + JSON.parse(result.responseText)["ErrMsg"]);
submitBtn.show(); submitBtn.show();
bar.hide(); bar.hide();
} else {
if (result.responseText["ImportStatus"] == 1) {
bar.hide();
statusBlock.show();
}
} }
}); });
}); });
......
Markdown is supported
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