Better error handling
This commit is contained in:
		
							parent
							
								
									7a0f783aa3
								
							
						
					
					
						commit
						43a0fa6c4f
					
				| @ -1 +0,0 @@ | |||||||
| gcc -std=c99 -o program.c program |  | ||||||
| @ -12,7 +12,7 @@ int main(int argc, const char *argv[]) | |||||||
| 
 | 
 | ||||||
|     // Standard library functions such as printf relay on the null-termination
 |     // Standard library functions such as printf relay on the null-termination
 | ||||||
|     char faulty[] = {'H', 'e', 'l', 'l', 'o'}; |     char faulty[] = {'H', 'e', 'l', 'l', 'o'}; | ||||||
|     // This will segfault
 |     // This might segfault
 | ||||||
|     printf("%s\n", faulty); |     printf("%s\n", faulty); | ||||||
|     // TODO: fix the char array definiton to avoid our programm segfaulting.
 |     // TODO: fix the char array definiton to avoid our programm segfaulting.
 | ||||||
|     // Why do we get a segmentation fault?
 |     // Why do we get a segmentation fault?
 | ||||||
|  | |||||||
| @ -1 +1 @@ | |||||||
| program/scriptgrade | program/match-regex | ||||||
|  | |||||||
| @ -33,8 +33,8 @@ def execute(ctx): | |||||||
|     if ctx.build_result[0] != 0: |     if ctx.build_result[0] != 0: | ||||||
|         return |         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(" ") |     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) |     print(" ".join(allArgs), file=sys.stderr) | ||||||
| 
 | 
 | ||||||
|     p = subprocess.Popen(allArgs, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=ctx.work_path) |     p = subprocess.Popen(allArgs, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=ctx.work_path) | ||||||
|     timeout = 1 |     timeout = 1 | ||||||
|  | |||||||
| @ -8,11 +8,10 @@ $(document).ready(function () { | |||||||
| 		html = ""; | 		html = ""; | ||||||
| 
 | 
 | ||||||
| 		if (type == "test") { | 		if (type == "test") { | ||||||
| 
 |  | ||||||
| 		} else { | 		} else { | ||||||
| 			if (msg.data.grade == "PASS") { | 			if (msg.data.grade == "PASS") { | ||||||
| 				html = '<div class="alert alert-success" role="alert"><strong>Great!</strong> Your solution is correct.<br/></div>'; | 				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") { | 			} else if (msg.data.grade == "FAIL") { | ||||||
| 				html = '<div class="alert alert-danger" role="alert"><strong>Sorry!</strong> That is not correct.<br/></div>'; | 				html = '<div class="alert alert-danger" role="alert"><strong>Sorry!</strong> That is not correct.<br/></div>'; | ||||||
| 			} else { | 			} else { | ||||||
| @ -21,9 +20,7 @@ $(document).ready(function () { | |||||||
| 				// a possible message that is generated yb the server to give tips?
 | 				// a possible message that is generated yb the server to give tips?
 | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 		//console.log(output)
 | ||||||
| 
 |  | ||||||
| 		console.log(output) |  | ||||||
| 		if ( output == "" ) { | 		if ( output == "" ) { | ||||||
| 			output = " " | 			output = " " | ||||||
| 		} | 		} | ||||||
| @ -45,7 +42,7 @@ $(document).ready(function () { | |||||||
| 
 | 
 | ||||||
| 	job = {} | 	job = {} | ||||||
| 	job.submit = function (action) { | 	job.submit = function (action) { | ||||||
| 
 | 		$("#output").html("Submitted ... Processing ..."); | ||||||
| 		//console.log("Test submission issued..");
 | 		//console.log("Test submission issued..");
 | ||||||
| 		//console.log( $("#c-code").val() );
 | 		//console.log( $("#c-code").val() );
 | ||||||
| 
 | 
 | ||||||
| @ -66,24 +63,22 @@ $(document).ready(function () { | |||||||
| 
 | 
 | ||||||
| 			job_id = msg['id']; | 			job_id = msg['id']; | ||||||
| 			setTimeout(function(){ job.status(action, job_id); }, 100); | 			setTimeout(function(){ job.status(action, job_id); }, 100); | ||||||
| 
 | 		}) | ||||||
|  | 		.error(function(jqXHR, textStatus, errorThrown ){ | ||||||
|  | 			response.show("test", "", "Error: " + errorThrown); | ||||||
| 		}); | 		}); | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
| 	job.status = function (type, job_id) { | 	job.status = function (type, job_id) { | ||||||
| 		//console.log(type)
 | 		//console.log(type)
 | ||||||
| 
 |  | ||||||
| 		e = {"blub": "hm"}; |  | ||||||
| 		json_data = JSON.stringify(e); |  | ||||||
| 
 |  | ||||||
| 		$.ajax({ | 		$.ajax({ | ||||||
| 			method: "GET", | 			method: "GET", | ||||||
| 			url: "/api/rest/job/" + job_id + "/", | 			url: "/api/rest/job/" + job_id + "/", | ||||||
| 			contentType: 'application/json', | 			contentType: 'application/json', | ||||||
| 		}) | 		}) | ||||||
| 		.done(function( msg ) { | 		.done(function( msg ) { | ||||||
| 			console.log("Status received: " + msg ); | 			//console.log("Status received: " + msg );
 | ||||||
| 			console.log(msg); | 			//console.log(msg);
 | ||||||
| 
 | 
 | ||||||
| 			if ( msg.status == 'SUCCESS' ) { | 			if ( msg.status == 'SUCCESS' ) { | ||||||
| 				response.show(type, msg, msg.data.output); | 				response.show(type, msg, msg.data.output); | ||||||
| @ -91,19 +86,21 @@ $(document).ready(function () { | |||||||
| 				response.show(type, "processing...", false); | 				response.show(type, "processing...", false); | ||||||
| 				setTimeout(function(){ job.status(type, job_id); }, 1000); | 				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").click(function(event) { | ||||||
| 		$("#submit-test").prop( "disabled", true); | 		//$("#submit-test").prop( "disabled", true);
 | ||||||
| 		job.submit("test"); | 		job.submit("test"); | ||||||
| 	}); | 	}); | ||||||
| 
 | 
 | ||||||
| 	$("#submit-grade").click(function(event) { | 	$("#submit-grade").click(function(event) { | ||||||
| 		$("#submit-grade").prop( "disabled", true); | 		//$("#submit-grade").prop( "disabled", true);
 | ||||||
| 		job.submit("grade"); | 		job.submit("grade"); | ||||||
| 	}); | 	}); | ||||||
| 
 | 
 | ||||||
| @ -113,7 +110,6 @@ $(document).ready(function () { | |||||||
| 		//$("#submit-test").prop( "disabled", true);
 | 		//$("#submit-test").prop( "disabled", true);
 | ||||||
| 		//job.submit("test");
 | 		//job.submit("test");
 | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 		target = event.target | 		target = event.target | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -123,10 +119,6 @@ $(document).ready(function () { | |||||||
| 			// also check/uncheck when clicking surounding
 | 			// 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) | 		console.log(target) | ||||||
| 		$(target).children("input").each(function () { this.checked = !this.checked; console.log(this) }); | 		$(target).children("input").each(function () { this.checked = !this.checked; console.log(this) }); | ||||||
| 		//$(target).toggleClass("list-group-item-success");
 | 		//$(target).toggleClass("list-group-item-success");
 | ||||||
|  | |||||||
| @ -27,8 +27,8 @@ def build(ctx): | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def execute(ctx): | def execute(ctx): | ||||||
|     allArgs = ['/usr/bin/make', 'execute'] |     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(" ") | ||||||
|     allArgs = ['./execute.sh'] |     print(" ".join(allArgs), file=sys.stderr) | ||||||
| 
 | 
 | ||||||
|     # start subprocess in with work_path as cwd |     # start subprocess in with work_path as cwd | ||||||
|     p = subprocess.Popen(allArgs, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=ctx.work_path) |     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 build failed, return early and set grade to FAIL | ||||||
|     if ctx.build_result[0] != 0: |     if ctx.build_result[0] != 0: | ||||||
|         return 'FAIL' |         return 'FAIL' | ||||||
| 
 |  | ||||||
|     print(ctx.execute_result, file=sys.stderr) |  | ||||||
| 
 |  | ||||||
|     allArgs = ['./test.sh'] |     allArgs = ['./test.sh'] | ||||||
|  |     print(" ".join(allArgs), file=sys.stderr) | ||||||
| 
 | 
 | ||||||
|     # start subprocess in with work_path as cwd |     # start subprocess in with work_path as cwd | ||||||
|     p = subprocess.Popen(allArgs, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=ctx.work_path) |     p = subprocess.Popen(allArgs, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=ctx.work_path) | ||||||
|  | |||||||
| @ -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 = " " |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		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");
 |  | ||||||
| 
 |  | ||||||
| 	}); |  | ||||||
| 
 |  | ||||||
| }); |  | ||||||
| 
 |  | ||||||
							
								
								
									
										1
									
								
								oer/exercise-formats/program/scriptgrade/script.js
									
									
									
									
									
										Symbolic link
									
								
							
							
						
						
									
										1
									
								
								oer/exercise-formats/program/scriptgrade/script.js
									
									
									
									
									
										Symbolic link
									
								
							| @ -0,0 +1 @@ | |||||||
|  | /data/oer/exercise-formats/program/match-regex/script.js | ||||||
| @ -1,4 +1,4 @@ | |||||||
| #!/usr/bin/bash | #!/bin/bash | ||||||
| 
 | 
 | ||||||
| source /data/run/virtualenv/bin/activate | source /data/run/virtualenv/bin/activate | ||||||
| cd /data/src | cd /data/src | ||||||
|  | |||||||
| @ -65,6 +65,8 @@ def section(request, cid, seid): | |||||||
|     course = get_object_or_404(Course, pk=cid) |     course = get_object_or_404(Course, pk=cid) | ||||||
|     section = get_object_or_404(Section, pk=seid) |     section = get_object_or_404(Section, pk=seid) | ||||||
|     first_slide = section.slides.first() |     first_slide = section.slides.first() | ||||||
|  |     #print(section.slides, file=sys.stderr) | ||||||
|  |     #print(first_slide, file=sys.stderr) | ||||||
| 
 | 
 | ||||||
|     if request.user.is_authenticated: |     if request.user.is_authenticated: | ||||||
|         try: |         try: | ||||||
| @ -97,8 +99,6 @@ def slide(request, cid, seid, slid): | |||||||
|     section = get_object_or_404(Section, pk=seid) |     section = get_object_or_404(Section, pk=seid) | ||||||
|     slide = get_object_or_404(Slide, pk=slid) |     slide = get_object_or_404(Slide, pk=slid) | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|     if request.user.is_authenticated: |     if request.user.is_authenticated: | ||||||
|         try: |         try: | ||||||
|             user_course = UserCourse.objects.get(course=course, user=request.user) |             user_course = UserCourse.objects.get(course=course, user=request.user) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user