Further cleanup

This commit is contained in:
Julian M. Kunkel 2018-05-06 11:35:06 +01:00
parent d82609737d
commit 4dd0c6986d
14 changed files with 186 additions and 371 deletions

View File

@ -61,7 +61,7 @@ $(document).ready(function () {
submission = {"solution": sol, "slide": window.data.slide, "action": "quiz"};
submission_json = JSON.stringify(submission);
console.log(submission_json)
//console.log(submission_json)
$.ajax({
method: "POST",
@ -72,45 +72,16 @@ $(document).ready(function () {
.done(function( msg ) {
console.log("Job submitted: " + msg );
console.log(msg);
job_id = msg['id'];
// really timeout?
// how about handling this directly?
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-grade").click(function(event) {
$("#submit-grade").click(function(event) {
$("#submit-grade").prop( "disabled", true);
job.submit("grade");
});
@ -123,11 +94,11 @@ $(document).ready(function () {
$("#exercise-choices a.list-group-item").click(function(event) {
event.preventDefault()
//$("#submit-test").prop( "disabled", true);
//job.submit("test");
//job.submit("test");
target = event.target
if ( $(target).is('input') ) {
target = $(event.target).parent()[0]
@ -135,7 +106,7 @@ $(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");
//}
@ -144,9 +115,8 @@ $(document).ready(function () {
$(target).children("input").each(function () { this.checked = !this.checked; console.log(this) });
//$(target).toggleClass("list-group-item-userchoice");
});
});

View File

@ -21,7 +21,7 @@ def build(ctx):
# start subprocess in with work_path as cwd
p = subprocess.Popen(allArgs, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=ctx.work_path)
msgs,errs = p.communicate()
retval = p.wait()
retval = p.wait()
errs = errs.decode("utf-8")
msgs = msgs.decode("utf-8")
@ -41,25 +41,23 @@ def execute(ctx):
p = subprocess.Popen(allArgs, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=ctx.work_path)
msgs,errs = p.communicate()
retval = p.wait()
retval = p.wait()
errs = errs.decode("utf-8")
msgs = msgs.decode("utf-8")
ctx.execute_result = (retval, errs, msgs)
#ctx.celery_task.update_state(state='SUBMITTED TO SLURM', meta=response(ctx))
ctx.celery_task.update_state(state='SUBMITTED TO SLURM', meta=response(ctx))
print("parallel execute(), before sleep", file=sys.stderr)
time.sleep(20)
print("parallel execute(), after sleep", file=sys.stderr)
#print("parallel execute(), before sleep", file=sys.stderr)
#time.sleep(20)
#print("parallel execute(), after sleep", file=sys.stderr)
retval = ctx.get_file_content('job.exit')
errs = ctx.get_file_content('job.err')
msgs = ctx.get_file_content('job.out')
print( (retval, errs, msgs), file=sys.stderr)
return retval, errs, msgs
@ -84,10 +82,10 @@ def grade(ctx):
else:
return 'FAIL'
def response(ctx):
output = ""
if ctx.build_result[0] != 0:
output = ctx.build_result[1]

View File

@ -10,6 +10,7 @@
import sys
import subprocess
import re
import time
def build(ctx):
@ -36,6 +37,16 @@ def execute(ctx):
allArgs = [ctx.programfile]
p = subprocess.Popen(allArgs, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=ctx.work_path)
timeout = 1
poll_period = 0.1
p.poll()
while p.returncode is None and timeout > 0:
time.sleep(poll_period)
timeout -= poll_period
p.poll()
if timeout <= 0:
p.kill() # timed out
msgs,errs = p.communicate()
retval = p.wait()

View File

@ -3,7 +3,7 @@ $(document).ready(function () {
response = {};
response.show = function (type, msg, output) {
console.log("show issued" + type + msg);
//console.log("show issued" + type + msg);
html = "";
@ -22,17 +22,17 @@ $(document).ready(function () {
}
}
console.log(output)
if ( output == "" ) {
output = "&nbsp;"
}
if ( output != false) {
console.log("output is not false")
//console.log("output is not false")
$("#output-wrapper").show(500);
$("#output").html(output);
}
}
$("#response").hide().html(html).show(500);
@ -46,13 +46,13 @@ $(document).ready(function () {
job = {}
job.submit = function (action) {
console.log("Test submission issued..");
console.log( $("#c-code").val() );
//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)
//console.log(submission_json)
$.ajax({
method: "POST",
@ -61,18 +61,17 @@ $(document).ready(function () {
data: submission_json
})
.done(function( msg ) {
console.log("Job submitted: " + msg );
console.log(msg);
//console.log("Job submitted: " + msg );
//console.log(msg);
job_id = msg['id'];
setTimeout(function(){ job.status(action, job_id); }, 1000);
setTimeout(function(){ job.status(action, job_id); }, 100);
});
});
};
job.status = function (type, job_id) {
console.log(type)
//console.log(type)
e = {"blub": "hm"};
json_data = JSON.stringify(e);
@ -90,7 +89,7 @@ $(document).ready(function () {
response.show(type, msg, msg.data.output);
} else {
response.show(type, "processing...", false);
setTimeout(function(){ job.status(type, job_id); }, 3000);
setTimeout(function(){ job.status(type, job_id); }, 1000);
}
});
@ -100,10 +99,10 @@ $(document).ready(function () {
$("#submit-test").click(function(event) {
$("#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);
job.submit("grade");
});
@ -112,11 +111,11 @@ $(document).ready(function () {
$("#exercise-choices a.list-group-item").click(function(event) {
event.preventDefault()
//$("#submit-test").prop( "disabled", true);
//job.submit("test");
//job.submit("test");
target = event.target
if ( $(target).is('input') ) {
target = $(event.target).parent()[0]
@ -135,4 +134,3 @@ $(document).ready(function () {
});
});

View File

@ -9,6 +9,7 @@
import sys
import subprocess
import re
import time
def build(ctx):
# Add filenames
@ -18,7 +19,7 @@ def build(ctx):
# start subprocess in with work_path as cwd
p = subprocess.Popen(allArgs, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=ctx.work_path)
msgs,errs = p.communicate()
retval = p.wait()
retval = p.wait()
errs = errs.decode("utf-8")
msgs = msgs.decode("utf-8")
@ -32,6 +33,16 @@ def execute(ctx):
# start subprocess in with work_path as cwd
p = subprocess.Popen(allArgs, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=ctx.work_path)
timeout = 1
poll_period = 0.1
p.poll()
while p.returncode is None and timeout > 0:
time.sleep(poll_period)
timeout -= poll_period
p.poll()
if timeout <= 0:
p.kill() # timed out
msgs,errs = p.communicate()
retval = p.wait()
@ -42,7 +53,7 @@ def execute(ctx):
def grade(ctx):
print("GRADING!!", file=sys.stderr)
#print("GRADING!!", file=sys.stderr)
# if build failed, return early and set grade to FAIL
if ctx.build_result[0] != 0:
@ -55,12 +66,22 @@ def grade(ctx):
# start subprocess in with work_path as cwd
p = subprocess.Popen(allArgs, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=ctx.work_path)
timeout = 1
poll_period = 0.1
p.poll()
while p.returncode is None and timeout > 0:
time.sleep(poll_period)
timeout -= poll_period
p.poll()
if timeout <= 0:
p.kill() # timed out
msgs,errs = p.communicate()
retval = p.wait()
retval = p.wait()
errs = errs.decode("utf-8")
msgs = msgs.decode("utf-8")
ctx.execute_result = (retval, errs, msgs)
@ -89,4 +110,3 @@ def response(ctx):
grade = ctx.grade_result
msg = ""
return {'output': output, 'grade': grade, 'msg': msg, 'data': None}

View File

@ -1,73 +1,6 @@
{% load staticfiles %}
{% load cookielaw_tags %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>Teaching - Scientific Computing @ UHH</title>
<!-- Bootstrap core CSS -->
<link href="{% static 'lib/bootstrap' %}/css/bootstrap.min.css" rel="stylesheet">
<link href="{% static 'frontend/index' %}/theme.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="{% static 'frontend/index' %}/jumbotron.css" rel="stylesheet">
<link href="{% static 'frontend/index' %}/styles.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
{% cookielaw_banner %}
{% include "frontend/navbar.html" %}
<div id="head-container">
<div id="dummy"></div>
<div id="element" style="background-image: url({% static 'frontend/drawing_nocredit.png' %}); background-size: 62.5% auto; background-repeat: repeat-x;">&nbsp;</div>
</div>
<!-- Main jumbotron for a primary marketing message or call to action -->
<!--
<div class="jumbotron">
<div class="container">
<h1>Welcome.</h1>
<p>This is a template for a simple marketing or informational website. It includes a large callout called a jumbotron and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
<p><a class="btn btn-primary btn-lg" href="#" role="button">Learn more &raquo;</a></p>
</div>
</div>
-->
<div class="container">
<!-- Example row of columns -->
{% include "frontend/header.html" %}
<div class="row">
</div>
<h1>Attribution</h1>
<p>In order to ensure a distraction free learning expierence references to work by third parties was ommited where possible.
@ -85,83 +18,6 @@
Please see the project details <a href="https://hps.vi4io.org/research/projects/hamburg/icp">here</a>.
</p>
<style type="text/css">
#hoou {
width: 175px;
height: 42px;
background: url('{% static 'misc' %}/hover-hoou.png') no-repeat left top;
background-size: 100% auto;
display: inline-block;
margin-right: 1.5em;
}
#hoou:hover { background-position: 0px 100% }
#uhh {
width: 155px;
height: 52px;
background: url('{% static 'misc' %}/hover-uhh.png') no-repeat left top;
background-size: 100% auto;
display: inline-block;
margin-right: 1.5em;
}
#uhh:hover { background-position: 0px 100% }
</style>
<h2>Images and Artworks</h2>
<p>The colorful header on top of the e.g. the entry page uses artworks created by multiple artists from <a href="https://thenounproject.com/">the Noun Project</a>:</p>
<ul>
<li>Created by <b><a href="">Lloyd Humphreys</a></b>:
<ul>
<li><a href="https://thenounproject.com/Lloyd/uploads/?i=96763">Computer</a></li>
<!-- <a href="https://thenounproject.com/Lloyd/collection/circuitry/">Cirtuity</a> -->
<li><a href="https://thenounproject.com/Lloyd/collection/circuitry/?i=96125">Light Emitting Diode</a></li>
<li><a href="https://thenounproject.com/Lloyd/collection/circuitry/?i=96166">Dual Gate Transistor</a></li>
<li><a href="https://thenounproject.com/Lloyd/collection/circuitry/?q=Inductor&i=96121">Inductor Bifflar</a></li>
<li><a href="https://thenounproject.com/Lloyd/collection/circuitry/?i=96143">Resistor</a></li>
<li><a href="https://thenounproject.com/Lloyd/uploads/?i=96678">Processor</a></li>
<li><a href="https://thenounproject.com/Lloyd/collection/circuitry/?q=Inductor&i=96121">Heavy Rain</a></li>
</ul>
</li>
<li>Created by <b><a href="https://thenounproject.com/alessandrantonetti/">alessandra antonetti</a></b>:
<ul>
<!-- https://thenounproject.com/ArtZ91/collection/blocks/ -->
<li><a href="https://thenounproject.com/search/?q=algorithm&creator=15311&i=204142">Cycle</a></li>
<li><a href="https://thenounproject.com/search/?q=algorithm&creator=15311&i=204132">Procedure</a></li>
<li><a href="https://thenounproject.com/search/?q=blocks&creator=15311&i=204135">Decomposition</a></li>
</ul>
</li>
<li>Created by <b><a href="https://thenounproject.com/ArtZ91/">Arthur Shlain</a></b>:
<ul>
<li><a href="https://thenounproject.com/alessandrantonetti/uploads/?i=31678">Circuit</a></li>
</ul>
</li>
<li>Created by <b><a href="https://thenounproject.com/creativestall/">Creative Stall</a></b>:
<ul>
<!--<li><a href="https://thenounproject.com/creativestall/collection/data-storage-server-and-transfer-material-icons/"></a></li> -->
<li><a href="https://thenounproject.com/search/?q=server&creator=638256&i=177061">Server</a></li>
<li><a href="https://thenounproject.com/search/?q=network&creator=638256&i=177026">Network</a></li>
<li><a href="https://thenounproject.com/search/?q=Servers&creator=638256&i=176934">Servers</a></li>
</ul>
</li>
</ul>
<h2>Software</h2>
<p>Several open source software projects enable the platform to operate. This section is dedicated to acknowledge the most important.</p>
@ -170,14 +26,10 @@
<li>The web application is build using <a href="https://www.djangoproject.com/">Django Web Framework</a>.</li>
<li>The code editor for many exercises with syntax highlight is based on <a href="https://codemirror.net/">CodeMirror</a>.</li>
</ul>
</div>
<hr>
<style type="text/css">
#hoou {
width: 175px;
@ -190,7 +42,6 @@
}
#hoou:hover { background-position: 0px 100% }
#uhh {
width: 155px;
height: 52px;
@ -201,66 +52,7 @@
margin-right: 1.5em;
}
#uhh:hover { background-position: 0px 100% }
#dkrz {
width: 147px;
height: 52px;
background: url('{% static 'misc' %}/hover-dkrz.png') no-repeat left top;
background-size: 100% auto;
display: inline-block;
margin-right: 1.5em;
}
#dkrz:hover { background-position: 0px 100% }
</style>
<div style="text-align: ;">
<!--
<a id="hoou" href="http://www.hoou.de/"></a><a id="uhh" href="http://www.uni-hamburg.de"></a><a id="dkrz" href="http://www.dkrz.de"></a>
-->
</div>
<!--
<img src="{% static 'misc' %}/logo-hoou.png" style="height: 50px;"/>
<span style="margin-left: 1em;">&nbsp;</span>
<img src="{% static 'misc' %}/logo-uhh.png" style="height: 60px;"/>
-->
<!-- <p>&copy; University of Hamburg</p> -->
{% include "frontend/footer.html" %}
</div> <!-- /container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="{% static 'lib/jquery.min.js' %}"></script>
<script src="{% static 'lib/bootstrap/js/bootstrap.min.js' %}"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="{% static 'lib/bootstrap/assets/js/ie10-viewport-bug-workaround.js' %}"></script>
<script src="{% static 'cookielaw/js/cookielaw.js' %}"></script>
</body>
</html>
{% include "frontend/footer.html" %}

View File

@ -22,3 +22,14 @@
<span class="sep">|</span>
<a href="/attribution">Attribution</a>
</footer>
</div> <!-- /container -->
<script src="{% static 'lib/jquery.min.js' %}"></script>
<script src="{% static 'lib/bootstrap/js/bootstrap.min.js' %}"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="{% static 'lib/bootstrap/assets/js/ie10-viewport-bug-workaround.js' %}"></script>
<script src="{% static 'cookielaw/js/cookielaw.js' %}"></script>
</body>
</html>

View File

@ -0,0 +1,30 @@
{% load staticfiles %}
{% load cookielaw_tags %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>Teaching @ HPS</title>
<!-- Bootstrap core CSS -->
<link href="{% static 'lib/bootstrap' %}/css/bootstrap.min.css" rel="stylesheet">
<link href="{% static 'frontend/index' %}/theme.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="{% static 'frontend/index' %}/jumbotron.css" rel="stylesheet">
<link href="{% static 'frontend/index' %}/styles.css" rel="stylesheet">
</head>
<body>
{% cookielaw_banner %}
{% include "frontend/navbar.html" %}
<div class="container">

View File

@ -1,73 +1,16 @@
{% load staticfiles %}
{% load cookielaw_tags %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>Teaching - Scientific Computing @ UHH</title>
<!-- Bootstrap core CSS -->
<link href="{% static 'lib/bootstrap' %}/css/bootstrap.min.css" rel="stylesheet">
<link href="{% static 'frontend/index' %}/theme.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="{% static 'frontend/index' %}/jumbotron.css" rel="stylesheet">
<link href="{% static 'frontend/index' %}/styles.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
{% cookielaw_banner %}
{% include "frontend/navbar.html" %}
<div id="head-container">
<div id="dummy"></div>
<div id="element" style="background-image: url({% static 'frontend/drawing_nocredit.png' %}); background-size: 62.5% auto; background-repeat: repeat-x;">&nbsp;</div>
</div>
<div class="container">
{% include "frontend/header.html" %}
<!-- Example row of columns -->
<div class="row">
{% for course in courses_list %}
<div class="col-md-4 course-listing">
<h2>{{ course.title }}</h2>
<p>{{ course.description }}</p>
<p><a class="btn btn-default" href="{% url 'courses:course' course.id %}" role="button">Take course &raquo;</a></p>
</div>
{% endfor %}
{% for course in courses_list %}
<div class="col-md-4 course-listing">
<h2>{{ course.title }}</h2>
<p>{{ course.description }}</p>
<p><a class="btn btn-default" href="{% url 'courses:course' course.id %}" role="button">Take course &raquo;</a></p>
</div>
{% endfor %}
</div>
<hr>
{% include "frontend/footer.html" %}
</div> <!-- /container -->
<script src="{% static 'lib/jquery.min.js' %}"></script>
<script src="{% static 'lib/bootstrap/js/bootstrap.min.js' %}"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="{% static 'lib/bootstrap/assets/js/ie10-viewport-bug-workaround.js' %}"></script>
<script src="{% static 'cookielaw/js/cookielaw.js' %}"></script>
</body>
</html>

View File

@ -10,7 +10,7 @@
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">
<b style="color: white;">Teaching</b> at
<b style="color: white;">Online teaching courses</b> at
<img src="https://hps.vi4io.org/_media/logo.png" style="height:1em; float:right; margin-left: 5px"/>
</a>
@ -60,8 +60,6 @@
<li><a href="{% url 'social:begin' 'twitter' %}?next={{ request.path }}"><i class="fa fa-twitter"></i> Login with Twitter</a>
<li><a href="{% url 'social:begin' 'google-oauth2' %}?next={{ request.path }}"><i class="fa fa-google-plus"></i> Login with Google+</a></li>
<li><a href="{% url 'social:begin' 'facebook' %}?next={{ request.path }}"><i class="fa fa-facebook"></i> Login with Facebook</a></li>
</ul>
</li>

View File

@ -0,0 +1,36 @@
{% load staticfiles %}
{% include "frontend/header.html" %}
<div class="row">
<h1>Privacy</h1>
<h2>Server logs</h2>
<p>
A visit to our website can result in the storage on our server of information about the access (date, time, page accessed). This does not represent any analysis of personal data (e.g., name, address or e-mail address). If personal data are collected, this only occurs to the extent possible with the prior consent of the user of the website. Any forwarding of the data to third parties without the express consent of the user shall not take place.
</p>
<h2>Uploaded information</h2>
<p>
This platform allows users to submit data for verification purpose like program code and quizes.
For improving the overall quality of the teaching experience, we may store and process the submitted information automatically.
If you are logged in as a user, the user id is also contained in this data.
If you do not like that your id is potentially stored together with the program code, we recommend to not login as a user but use the platform anonymously.
</p>
<h2>Information about cookies</h2>
<ul>
<li>To optimize our web presence, we may use cookies. These are small text files stored in your computer's main memory. These cookies are deleted after you close the browser.</li>
<li>Other cookies remain on your computer (long-term cookies) and permit its recognition on your next visit. This allows us to improve your access to our site.</li>
<li>You can prevent storage of cookies by choosing a “disable cookies” option in your browser settings. But this can limit the functionality of our Internet offers as a result.</li>
</ul>
<h2>Contact</h2>
<p>
If you have any questions regarding privacy send an email to: <a href="mailto:info@oer.hps.vi4io.org">info@oer.hps.vi4io.org</a>
</p>
</div>
{% include "frontend/footer.html" %}

View File

@ -23,7 +23,7 @@ SECRET_KEY = 'pxf234t25323vasfk3t202v2232v124'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
DEBUG = True
#DEBUG = True
ALLOWED_HOSTS = ['localhost', 'oer.hps.vi4io.org']

View File

@ -28,6 +28,7 @@ import os
import pprint
import re
import os.path
import shutil
from courses.models import Course
from courses.models import Section
@ -38,20 +39,32 @@ from courses.models import UserSolution
from runner.tasks import compile_and_run
import json
import random
def local_execute(dic):
#print("LOCAL EXECUTE")
id = 100
id = random.randint(1,10000000)
file = "/data/run/jobs/%s/job.json" % (id)
while os.path.isfile(file):
id = random.randint(1,10000000)
file = "/data/run/jobs/%s/job.json" % (id)
ret = compile_and_run(id, dic)
print(ret, file=sys.stderr)
return {"status" : 'SUCCESS', "id" : id, "result": ret}
return {"details": "OK", "id" : id, "data": ret}
def local_execute_result(id):
#return {"status" : 201, "result": {"output" : False, "grade" : "PASS"}}
file = "/data/run/jobs/%s/job.json" % (id)
print("Retrieving: " + file)
if os.path.isfile(file):
with open(file) as json_data:
if not id.isdigit():
return {"status" : 0, "result": {"output" : False}}
dir = "/data/run/jobs/%s/" % (id)
print("Retrieving: " + dir)
if os.path.isfile(dir + "job.json"):
with open(dir + "job.json") as json_data:
d = json.load(json_data)
# cleanup of outdated directories
shutil.rmtree(dir)
return {"status" : 'SUCCESS', "result": d["response"]}
else:
return {"status" : 0, "result": {"output" : False}}
@ -248,19 +261,11 @@ def job_new(request):
try:
#task = celery_task_compile_and_run.delay(job_dic)
task = local_execute(job_dic)
#print(dir(task), file=sys.stderr)
#print("PREP")
#print(task.id, file=sys.stderr)
#print(task.status, file=sys.stderr)
job_dic["_id"] = task["id"]
#print("DONE")
data = local_execute(job_dic)
#_id = job_col.insert(request.data)
#print(_id, file=sys.stderr)
#json_docs = json.dumps(data, default=json_util.default)
return JSONResponse({"details": "OK", "id": str(task["id"])}, status=201)
return JSONResponse(data, status=201)
except:
print(sys.exc_info()[0])
return JSONResponse({"details": "Job submission failed."}, status=400)

View File

@ -230,6 +230,9 @@ def compile_and_run(id, data):
if data['action'] in ["grade", "quiz"]:
j.grade()
if data['action'] == "quiz":
return {"grade" : j.grade_result }
#print("Result prepare")
ret = j.response()
j.response_data = ret