Merge pull request #359 from FirmlyReality/batch

Beautify the batch_output page & make it update in every two seconds
This commit is contained in:
Yujian Zhu 2018-12-01 17:08:12 +08:00 committed by GitHub
commit 806e4d583c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 79 additions and 5 deletions

View File

@ -1,5 +1,6 @@
import time, threading, random, string, os, traceback
import master.monitor
import subprocess
from utils.log import initlogging, logger
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)
logger.info("Get output from:%s" % fpath)
try:
file = open(fpath)
output = file.read()
ret = subprocess.run('tail -n 100 ' + fpath,stdout=subprocess.PIPE,stderr=subprocess.STDOUT, shell=True)
if ret.returncode != 0:
raise IOError(ret.stdout.decode(encoding="utf-8"))
except Exception as err:
logger.error(traceback.format_exc())
return ""
else:
return output
return ret.stdout.decode(encoding="utf-8")

View File

@ -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>

View File

@ -158,6 +158,18 @@ def output_batch_job(jobid, taskid, instid, issue):
outputBatchJobView.issue = issue
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'])
#@activated_required
def addCluster():

View File

@ -53,7 +53,7 @@ class addBatchJobView(normalView):
return self.error()
class outputBatchJobView(normalView):
#template_path = "batch/batch_output.html"
template_path = "batch/batch_output.html"
jobid = ""
taskid = ""
instid = ""
@ -72,6 +72,7 @@ class outputBatchJobView(normalView):
output = result.get("data")
#logger.debug("job_list: %s" % job_list)
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:
return self.error()