Add infos to job model and show them on the job info pages.

This commit is contained in:
Patrick Jentsch 2019-08-09 15:59:53 +02:00
parent 359baf0297
commit a302d08405
5 changed files with 109 additions and 12 deletions

View File

@ -71,4 +71,30 @@ def job(job_id):
elif not job.user_id == current_user.id: elif not job.user_id == current_user.id:
print('Job does not belong to current user.') print('Job does not belong to current user.')
abort(403) abort(403)
return render_template('main/jobs/job.html.j2', title='Job', job=job) input_dir = os.path.join(current_app.config['OPAQUE_STORAGE'],
str(current_user.id),
'jobs',
str(job.id))
output_dir = os.path.join(current_app.config['OPAQUE_STORAGE'],
str(current_user.id),
'jobs',
str(job.id),
'output')
input_files = {}
for file in os.listdir(input_dir):
if file == 'output':
continue
input_files[file] = os.path.join(input_dir, file)
output_files = {}
if job.status == 'complete':
for input_file in input_files:
dir = os.path.join(output_dir, input_file)
for output_file in os.listdir(dir):
output_files[output_file] = os.path.join(dir, output_file)
return render_template('main/jobs/job.html.j2',
input_files=input_files,
job=job,
output_files=output_files, title='Job')

View File

@ -222,6 +222,7 @@ class Job(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
creation_date = db.Column(db.DateTime(), default=datetime.utcnow) creation_date = db.Column(db.DateTime(), default=datetime.utcnow)
description = db.Column(db.String(255)) description = db.Column(db.String(255))
end_date = db.Column(db.DateTime())
mem_mb = db.Column(db.Integer) mem_mb = db.Column(db.Integer)
n_cores = db.Column(db.Integer) n_cores = db.Column(db.Integer)
service = db.Column(db.String(64)) service = db.Column(db.String(64))

View File

@ -73,7 +73,6 @@ def ocr():
service='ocr', service='ocr',
service_args=json.dumps([ service_args=json.dumps([
'-l {}'.format(new_ocr_job_form.language.data), '-l {}'.format(new_ocr_job_form.language.data),
'--keep-intermediates',
'--skip-binarisation']), '--skip-binarisation']),
service_version=new_ocr_job_form.version.data, service_version=new_ocr_job_form.version.data,
status='submitted', status='submitted',

View File

@ -1,3 +1,4 @@
from datetime import datetime
from sqlalchemy import create_engine from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker from sqlalchemy.orm import sessionmaker
import docker import docker
@ -110,6 +111,7 @@ class Swarm:
break break
time.sleep(1) time.sleep(1)
service.reload() service.reload()
job.end_date = datetime.utcnow()
job.status = current_state job.status = current_state
session.commit() session.commit()
session.close() session.close()

View File

@ -4,21 +4,90 @@
<div class="col s12 m4"> <div class="col s12 m4">
<h3>{{ job.title }}</h3> <h3>{{ job.title }}</h3>
<p>{{ job.description }}</p> <p>{{ job.description }}</p>
{% if job.status == 'pending' %}
{% set status_color = 'amber' %}
{% elif job.status =='running' %}
{% set status_color = 'indigo' %}
{% elif job.status =='complete' %}
{% set status_color = 'teal' %}
{% else %}
{% set status_color = 'red' %}
{% endif %}
<p><a class="waves-effect waves-light btn {{ status_color }}">{{ job.status }}</a></p>
</div> </div>
<div class="col s12 m8"> <div class="col s12 m8">
<div class="card"> <div class="card">
<div class="card-content"> <div class="card-content">
<span class="card-title">Details</span> <span class="card-title">Chronometrics</span>
<p><b>Creation date</b>: {{ job.creation_date }}</p> <div class="row">
<p><b>Description</b>: {{ job.description }}</p> <div class="col s12 m6">
<p><b>Memory</b>: {{ job.mem_mb }} MB</p> <div class="input-field">
<p><b>Cores</b>: {{ job.n_cores }}</p> <input disabled value="{{ job.creation_date }}" id="creation-date" type="text" class="validate">
<p><b>Service</b>: {{ job.service }}</p> <label for="creation-date">Creation date</label>
<p><b>Service arguments</b>: {{ job.service_args }}</p> </div>
<p><b>Service version</b>: {{ job.service_version }}</p> </div>
<p><b>Status</b>: {{ job.status }}</p> <div class="col s12 m6">
<p><b>Title</b>: {{ job.title }}</p> <div class="input-field">
<input disabled value="{{ job.end_date }}" id="end-date" type="text" class="validate">
<label for="end-date">End date</label>
</div>
</div>
</div>
<span class="card-title">Ressource allocations</span>
<div class="row">
<div class="col s12 m6">
<div class="input-field">
<input disabled value="{{ job.mem_mb }}" id="mem-mb" type="text" class="validate">
<label for="mem-mb">Memory</label>
</div>
</div>
<div class="col s12 m6">
<div class="input-field">
<input disabled value="{{ job.n_cores }}" id="n-cores" type="text" class="validate">
<label for="n-cores">CPU cores</label>
</div>
</div>
</div>
<span class="card-title">Service informations</span>
<div class="row">
<div class="col s12 m4">
<div class="input-field">
<input disabled value="{{ job.service }}" id="service" type="text" class="validate">
<label for="service">Service</label>
</div>
</div>
<div class="col s12 m4">
<div class="input-field">
<input disabled value="{{ job.service_args|escape }}" id="service-args" type="text" class="validate">
<label for="service-args">Service arguments</label>
</div>
</div>
<div class="col s12 m4">
<div class="input-field">
<input disabled value="{{ job.service_version }}" id="service-version" type="text" class="validate">
<label for="service-version">Service version</label>
</div>
</div>
</div>
<p>
{% for file in input_files %}
<a href="file://{{ input_files[file] }}" class="waves-effect waves-light btn-small">
<i class="material-icons left">file_download</i>{{ file }}
</a>
{% endfor %}
</p>
<p>&nbsp;</p>
<span class="card-title">Results</span>
<p>
{% for file in output_files %}
<a href="file://{{ output_files[file] }}" class="waves-effect waves-light btn-small">
<i class="material-icons left">file_download</i>{{ file }}
</a>
{% endfor %}
</p>
</div> </div>
</div> </div>