Merge pull request #359 from FirmlyReality/batch
Beautify the batch_output page & make it update in every two seconds
This commit is contained in:
commit
806e4d583c
|
@ -1,5 +1,6 @@
|
||||||
import time, threading, random, string, os, traceback
|
import time, threading, random, string, os, traceback
|
||||||
import master.monitor
|
import master.monitor
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from utils.log import initlogging, logger
|
from utils.log import initlogging, logger
|
||||||
from utils import env
|
from utils import env
|
||||||
|
@ -169,10 +170,11 @@ class JobMgr(threading.Thread):
|
||||||
fpath = "%s/global/users/%s/data/batch_%s/%s" % (self.fspath,username,jobid,filename)
|
fpath = "%s/global/users/%s/data/batch_%s/%s" % (self.fspath,username,jobid,filename)
|
||||||
logger.info("Get output from:%s" % fpath)
|
logger.info("Get output from:%s" % fpath)
|
||||||
try:
|
try:
|
||||||
file = open(fpath)
|
ret = subprocess.run('tail -n 100 ' + fpath,stdout=subprocess.PIPE,stderr=subprocess.STDOUT, shell=True)
|
||||||
output = file.read()
|
if ret.returncode != 0:
|
||||||
|
raise IOError(ret.stdout.decode(encoding="utf-8"))
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.error(traceback.format_exc())
|
logger.error(traceback.format_exc())
|
||||||
return ""
|
return ""
|
||||||
else:
|
else:
|
||||||
return output
|
return ret.stdout.decode(encoding="utf-8")
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<title>Docklet | Batch {{ issue }}: {{ jobid }}/{{ taskid }}/{{ instid }}</title>
|
||||||
|
<!-- Tell the browser to be responsive to screen width -->
|
||||||
|
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
|
||||||
|
<link rel="shortcut icon" href="/static/img/favicon.ico">
|
||||||
|
|
||||||
|
<link href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
|
||||||
|
<!-- Font Awesome -->
|
||||||
|
<link href="//cdn.bootcss.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
|
||||||
|
|
||||||
|
<!-- Ionicons -->
|
||||||
|
<link href="//cdn.bootcss.com/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet">
|
||||||
|
|
||||||
|
<link href="//cdn.bootcss.com/animate.css/3.5.1/animate.min.css" rel="stylesheet">
|
||||||
|
<link href="//cdn.bootcss.com/toastr.js/latest/css/toastr.min.css" rel="stylesheet">
|
||||||
|
|
||||||
|
<!-- Theme style -->
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="/static/dist/css/AdminLTE.min.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="/static/dist/css/skins/skin-blue.min.css">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h3>Jobid: {{ jobid }}</h3>
|
||||||
|
<h3>Taskid: {{ taskid }}</h3>
|
||||||
|
<h3>Instanceid: {{ instid }}</h3>
|
||||||
|
<h4><small>The output of {{ issue }} will be updated in every 2 seconds.</small></h4>
|
||||||
|
<hr>
|
||||||
|
<pre id="output">{{ output }}</pre>
|
||||||
|
<!-- jQuery 2.2.1 -->
|
||||||
|
<script src="//cdn.bootcss.com/jquery/2.2.1/jquery.min.js"></script>
|
||||||
|
<!-- Bootstrap 3.3.5 -->
|
||||||
|
<script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
|
||||||
|
<!-- AdminLTE App -->
|
||||||
|
<script src="/static/dist/js/app.min.js"></script>
|
||||||
|
|
||||||
|
<script src="//cdn.bootcss.com/fastclick/1.0.6/fastclick.min.js"></script>
|
||||||
|
<script src="//cdn.bootcss.com/jQuery-slimScroll/1.3.7/jquery.slimscroll.min.js"></script>
|
||||||
|
<script src="//cdn.bootcss.com/toastr.js/latest/js/toastr.min.js"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
function updateOutput()
|
||||||
|
{
|
||||||
|
var host = window.location.host;
|
||||||
|
url = "http://" + host + "/batch/job/output/" + "{{ masterip }}" + "/" + "{{ jobid }}" + "/" + "{{ taskid }}" + "/" + "{{ instid }}" + "/" + "{{ issue }}" + "/";
|
||||||
|
$.post(url,{},function(data){
|
||||||
|
$("#output").html(data.data);
|
||||||
|
},"json");
|
||||||
|
}
|
||||||
|
setInterval(updateOutput,2000);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
12
web/web.py
12
web/web.py
|
@ -158,6 +158,18 @@ def output_batch_job(jobid, taskid, instid, issue):
|
||||||
outputBatchJobView.issue = issue
|
outputBatchJobView.issue = issue
|
||||||
return outputBatchJobView().as_view()
|
return outputBatchJobView().as_view()
|
||||||
|
|
||||||
|
@app.route("/batch/job/output/<masterip>/<jobid>/<taskid>/<instid>/<issue>/", methods=['POST'])
|
||||||
|
@login_required
|
||||||
|
def output_batch_job_request(masterip, jobid, taskid, instid, issue):
|
||||||
|
data = {
|
||||||
|
'jobid':jobid,
|
||||||
|
'taskid':taskid,
|
||||||
|
'instid':instid,
|
||||||
|
'issue':issue
|
||||||
|
}
|
||||||
|
result = dockletRequest.post("/batch/job/output/",data,masterip)
|
||||||
|
return json.dumps(result)
|
||||||
|
|
||||||
@app.route("/workspace/create/", methods=['GET'])
|
@app.route("/workspace/create/", methods=['GET'])
|
||||||
#@activated_required
|
#@activated_required
|
||||||
def addCluster():
|
def addCluster():
|
||||||
|
|
|
@ -53,7 +53,7 @@ class addBatchJobView(normalView):
|
||||||
return self.error()
|
return self.error()
|
||||||
|
|
||||||
class outputBatchJobView(normalView):
|
class outputBatchJobView(normalView):
|
||||||
#template_path = "batch/batch_output.html"
|
template_path = "batch/batch_output.html"
|
||||||
jobid = ""
|
jobid = ""
|
||||||
taskid = ""
|
taskid = ""
|
||||||
instid = ""
|
instid = ""
|
||||||
|
@ -72,6 +72,7 @@ class outputBatchJobView(normalView):
|
||||||
output = result.get("data")
|
output = result.get("data")
|
||||||
#logger.debug("job_list: %s" % job_list)
|
#logger.debug("job_list: %s" % job_list)
|
||||||
if result.get('success',"") == "true":
|
if result.get('success',"") == "true":
|
||||||
return "<pre>" + output + "</pre>"
|
return self.render(self.template_path, masterip=masterips[0].split("@")[0], jobid=self.jobid,
|
||||||
|
taskid=self.taskid, instid=self.instid, issue=self.issue, output=output)
|
||||||
else:
|
else:
|
||||||
return self.error()
|
return self.error()
|
||||||
|
|
Loading…
Reference in New Issue