Better error handling

master
Julian M. Kunkel 2018-05-06 13:50:31 +01:00
parent 7a0f783aa3
commit 43a0fa6c4f
12 changed files with 24 additions and 172 deletions

View File

@ -1 +0,0 @@
gcc -std=c99 -o program.c program

View File

@ -12,7 +12,7 @@ int main(int argc, const char *argv[])
// Standard library functions such as printf relay on the null-termination
char faulty[] = {'H', 'e', 'l', 'l', 'o'};
// This will segfault
// This might segfault
printf("%s\n", faulty);
// TODO: fix the char array definiton to avoid our programm segfaulting.
// Why do we get a segmentation fault?

View File

@ -1 +1 @@
program/scriptgrade
program/match-regex

View File

@ -33,8 +33,8 @@ def execute(ctx):
if ctx.build_result[0] != 0:
return
allArgs = ("/usr/bin/docker run -h oer-worker --user 1001:65534 --rm -v /data/run/jobs/%s/:/data/ kunkel/oer-worker /data/program" % ctx.id).split(" ")
#print(" ".join(allArgs), file=sys.stderr)
allArgs = ("/usr/bin/docker run -h oer-worker --user 1001:65534 --rm -v /data/run/jobs/%s/:/data/ --network none kunkel/oer-worker /data/program" % ctx.id).split(" ")
print(" ".join(allArgs), file=sys.stderr)
p = subprocess.Popen(allArgs, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=ctx.work_path)
timeout = 1

View File

@ -8,11 +8,10 @@ $(document).ready(function () {
html = "";
if (type == "test") {
} else {
if (msg.data.grade == "PASS") {
html = '<div class="alert alert-success" role="alert"><strong>Great!</strong> Your solution is correct.<br/></div>';
$("#continue").prop( "disabled", false);
//$("#continue").prop( "disabled", false);
} else if (msg.data.grade == "FAIL") {
html = '<div class="alert alert-danger" role="alert"><strong>Sorry!</strong> That is not correct.<br/></div>';
} else {
@ -21,9 +20,7 @@ $(document).ready(function () {
// a possible message that is generated yb the server to give tips?
}
}
console.log(output)
//console.log(output)
if ( output == "" ) {
output = "&nbsp;"
}
@ -45,7 +42,7 @@ $(document).ready(function () {
job = {}
job.submit = function (action) {
$("#output").html("Submitted ... Processing ...");
//console.log("Test submission issued..");
//console.log( $("#c-code").val() );
@ -66,24 +63,22 @@ $(document).ready(function () {
job_id = msg['id'];
setTimeout(function(){ job.status(action, job_id); }, 100);
})
.error(function(jqXHR, textStatus, errorThrown ){
response.show("test", "", "Error: " + errorThrown);
});
};
job.status = function (type, job_id) {
//console.log(type)
e = {"blub": "hm"};
json_data = JSON.stringify(e);
$.ajax({
method: "GET",
url: "/api/rest/job/" + job_id + "/",
contentType: 'application/json',
})
.done(function( msg ) {
console.log("Status received: " + msg );
console.log(msg);
//console.log("Status received: " + msg );
//console.log(msg);
if ( msg.status == 'SUCCESS' ) {
response.show(type, msg, msg.data.output);
@ -91,19 +86,21 @@ $(document).ready(function () {
response.show(type, "processing...", false);
setTimeout(function(){ job.status(type, job_id); }, 1000);
}
})
.error(function(jqXHR, textStatus, errorThrown ){
response.show("test", "", "Error: " + errorThrown);
});
};
$("#submit-test").click(function(event) {
$("#submit-test").prop( "disabled", true);
//$("#submit-test").prop( "disabled", true);
job.submit("test");
});
$("#submit-grade").click(function(event) {
$("#submit-grade").prop( "disabled", true);
//$("#submit-grade").prop( "disabled", true);
job.submit("grade");
});
@ -113,7 +110,6 @@ $(document).ready(function () {
//$("#submit-test").prop( "disabled", true);
//job.submit("test");
target = event.target
@ -123,10 +119,6 @@ $(document).ready(function () {
// also check/uncheck when clicking surounding
}
//if ( $(target).children("input").attr('type') == 'radio' ) {
// $(target).parent().children(".list-group-item-success").removeClass("list-group-item-success");
//}
console.log(target)
$(target).children("input").each(function () { this.checked = !this.checked; console.log(this) });
//$(target).toggleClass("list-group-item-success");

View File

@ -27,8 +27,8 @@ def build(ctx):
def execute(ctx):
allArgs = ['/usr/bin/make', 'execute']
allArgs = ['./execute.sh']
allArgs = ("/usr/bin/docker run -h oer-worker --user 1001:65534 --rm -v /data/run/jobs/%s/:/data/ --network none kunkel/oer-worker /data/execute.sh" % ctx.id).split(" ")
print(" ".join(allArgs), file=sys.stderr)
# start subprocess in with work_path as cwd
p = subprocess.Popen(allArgs, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=ctx.work_path)
@ -57,10 +57,8 @@ def grade(ctx):
# if build failed, return early and set grade to FAIL
if ctx.build_result[0] != 0:
return 'FAIL'
print(ctx.execute_result, file=sys.stderr)
allArgs = ['./test.sh']
print(" ".join(allArgs), file=sys.stderr)
# start subprocess in with work_path as cwd
p = subprocess.Popen(allArgs, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=ctx.work_path)

View File

@ -1,138 +0,0 @@
$(document).ready(function () {
response = {};
response.show = function (type, msg, output) {
console.log("show issued" + type + msg);
html = "";
if (type == "test") {
} else {
if (msg.data.grade == "PASS") {
html = '<div class="alert alert-success" role="alert"><strong>Great!</strong> Your solution is correct.<br/></div>';
$("#continue").prop( "disabled", false);
} else if (msg.data.grade == "FAIL") {
html = '<div class="alert alert-danger" role="alert"><strong>Sorry!</strong> That is not correct.<br/></div>';
} else {
// assume test
//html = msg;
// a possible message that is generated yb the server to give tips?
}
}
console.log(output)
if ( output == "" ) {
output = "&nbsp;"
}
if ( output != false) {
console.log("output is not false")
$("#output-wrapper").show(500);
$("#output").html(output);
}
$("#response").hide().html(html).show(500);
$("#submit-test").prop( "disabled", false);
$("#submit-grade").prop( "disabled", false);
}
job = {}
job.submit = function (action) {
console.log("Test submission issued..");
console.log( $("#c-code").val() );
submission = {"solution": cEditor.getValue(), "cmd": "run.sh", "action": action, "slide": window.data.slide};
submission_json = JSON.stringify(submission);
console.log(submission_json)
$.ajax({
method: "POST",
url: "/api/rest/job/new/",
contentType: 'application/json',
data: submission_json
})
.done(function( msg ) {
console.log("Job submitted: " + msg );
console.log(msg);
job_id = msg['id'];
setTimeout(function(){ job.status(action, job_id); }, 1000);
});
};
job.status = function (type, job_id) {
console.log(type)
e = {"blub": "hm"};
json_data = JSON.stringify(e);
$.ajax({
method: "GET",
url: "/api/rest/job/" + job_id + "/",
contentType: 'application/json',
})
.done(function( msg ) {
console.log("Status received: " + msg );
console.log(msg);
if ( msg.status == 'SUCCESS' ) {
response.show(type, msg, msg.data.output);
} else {
response.show(type, "processing...", false);
setTimeout(function(){ job.status(type, job_id); }, 3000);
}
});
};
$("#submit-test").click(function(event) {
$("#submit-test").prop( "disabled", true);
job.submit("test");
});
$("#submit-grade").click(function(event) {
$("#submit-grade").prop( "disabled", true);
job.submit("grade");
});
$("#exercise-choices a.list-group-item").click(function(event) {
event.preventDefault()
//$("#submit-test").prop( "disabled", true);
//job.submit("test");
target = event.target
if ( $(target).is('input') ) {
target = $(event.target).parent()[0]
} else {
// also check/uncheck when clicking surounding
}
//if ( $(target).children("input").attr('type') == 'radio' ) {
// $(target).parent().children(".list-group-item-success").removeClass("list-group-item-success");
//}
console.log(target)
$(target).children("input").each(function () { this.checked = !this.checked; console.log(this) });
//$(target).toggleClass("list-group-item-success");
});
});

View File

@ -0,0 +1 @@
/data/oer/exercise-formats/program/match-regex/script.js

View File

@ -1,4 +1,4 @@
#!/usr/bin/bash
#!/bin/bash
source /data/run/virtualenv/bin/activate
cd /data/src

View File

@ -65,6 +65,8 @@ def section(request, cid, seid):
course = get_object_or_404(Course, pk=cid)
section = get_object_or_404(Section, pk=seid)
first_slide = section.slides.first()
#print(section.slides, file=sys.stderr)
#print(first_slide, file=sys.stderr)
if request.user.is_authenticated:
try:
@ -97,8 +99,6 @@ def slide(request, cid, seid, slid):
section = get_object_or_404(Section, pk=seid)
slide = get_object_or_404(Slide, pk=slid)
if request.user.is_authenticated:
try:
user_course = UserCourse.objects.get(course=course, user=request.user)