Commit fcd11d93 by Julian Arni

Handle nginx 499s and double requests

parent 8a8bcf28
......@@ -89,16 +89,20 @@ def import_course(request, org, course, name):
# Check to make sure we haven't missed a chunk
# This shouldn't happen, even if different instances are handling
# 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(
"Reported range %s does not match size downloaded so far %s",
size,
content_range['start']
content_range['start'],
size
)
return JsonResponse(
{'ErrMsg': 'File upload corrupted. Please try again'},
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:
for chunk in request.FILES['course-data'].chunks():
......
......@@ -57,6 +57,11 @@ body.course.import {
color: $error-red;
}
.status-block {
display: none;
font-size: 13px;
}
.choose-file-button {
@include blue-button;
padding: 10px 50px 11px;
......
......@@ -34,6 +34,7 @@
<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="hidden" name="csrfmiddlewaretoken" value="${csrf_token}">
<p class="status-block">Unpacking...</p>
<div class="progress-bar">
<div class="progress-fill"></div>
<div class="percent">0%</div>
......@@ -55,6 +56,7 @@ var bar = $('.progress-bar');
var fill = $('.progress-fill');
var percent = $('.percent');
var status = $('#status');
var statusBlock = $('.status-block');
var submitBtn = $('.submit-button');
......@@ -79,6 +81,11 @@ $('#fileupload').fileupload({
alert('${_("Your import has failed.")}\n\n' + JSON.parse(result.responseText)["ErrMsg"]);
submitBtn.show();
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