Map task states to job status. Colorize status badges on dashboard.

This commit is contained in:
Patrick Jentsch 2019-08-07 15:01:37 +02:00
parent 267f86d342
commit 6f8cef26e4
3 changed files with 30 additions and 17 deletions

View File

@ -25,7 +25,7 @@ def ocr():
"--skip-binarisation"], "--skip-binarisation"],
"lang": new_ocr_job_form.language.data, "lang": new_ocr_job_form.language.data,
"version": new_ocr_job_form.version.data}), "version": new_ocr_job_form.version.data}),
status="submitted", status="pending",
title=new_ocr_job_form.title.data) title=new_ocr_job_form.title.data)
db.session.add(ocr_job) db.session.add(ocr_job)
db.session.commit() db.session.commit()
@ -74,7 +74,7 @@ def nlp():
service_args=json.dumps({"args": [], service_args=json.dumps({"args": [],
"lang": new_nlp_job_form.language.data, "lang": new_nlp_job_form.language.data,
"version": new_nlp_job_form.version.data}), "version": new_nlp_job_form.version.data}),
status="submitted", status="pending",
title=new_nlp_job_form.title.data) title=new_nlp_job_form.title.data)
db.session.add(nlp_job) db.session.add(nlp_job)
db.session.commit() db.session.commit()

View File

@ -101,16 +101,19 @@ class Swarm:
' Poll the service until the job is completly executed. ' Poll the service until the job is completly executed.
''' '''
session = self.Session() session = self.Session()
job.status = 'running'
session.add(job)
session.commit()
current_state = None
while True: while True:
current_state = service.tasks()[0].get('Status').get('State') current_state = service.tasks()[0].get('Status').get('State')
if job.status != current_state: if current_state == 'complete' or current_state == 'failed':
job.status = current_state
session.add(job)
session.commit()
if current_state == 'complete':
break break
time.sleep(1) time.sleep(1)
service.reload() service.reload()
job.status = current_state
session.add(job)
session.commit()
session.close() session.close()
# Remove the service from the swarm. # Remove the service from the swarm.
service.remove() service.remove()

View File

@ -58,17 +58,27 @@
</div> </div>
</li> </li>
{% for job in current_user.jobs.all() %} {% for job in current_user.jobs.all() %}
{% if job.service == 'nlp' %}
{% set service_icon = 'format_textdirection_l_to_r' %}
{% elif job.service =='ocr' %}
{% set service_icon = 'find_in_page' %}
{% else %}
{% set service_icon = 'help' %}
{% endif %}
{% if job.status == 'pending' %}
{% set badge_color = 'amber' %}
{% elif job.status =='running' %}
{% set badge_color = 'indigo' %}
{% elif job.status =='complete' %}
{% set badge_color = 'teal' %}
{% else %}
{% set badge_color = 'red' %}
{% endif %}
<li class="collection-item avatar"> <li class="collection-item avatar">
<i class="material-icons circle"> <i class="material-icons circle">{{ service_icon }}</i>
{% if job.service == 'nlp' %} <span class="new badge {{ badge_color }}" data-badge-caption="">{{ job.status }}</span>
format_textdirection_l_to_r
{% elif job.service =='ocr' %}
find_in_page
{% else %}
help
{% endif %}
</i>
<span class="new badge teal" data-badge-caption="">{{ job.status }}</span>
<span class="title">{{ job.title }}</span> <span class="title">{{ job.title }}</span>
<p>{{ job.description }}</p> <p>{{ job.description }}</p>
</li> </li>