joblog rewrite to show only a few "newest" lines and "oldest" logs for a job, with the more button in the middle, also has a little icon to show the re-ordering that goes with each view - should really make this clickable/togglable.

This commit is contained in:
2022-01-13 21:12:09 +11:00
parent 10866c3147
commit 8a6a7a5115
6 changed files with 47 additions and 19 deletions

3
TODO
View File

@@ -4,6 +4,9 @@
- [DONE] force scans of import/storage paths
- [DONE] delete old files from Recycle Bin
- need to archive jobs
--> joblog page should show last 25 logs, <show all button>, newest 25 logs, need to use sm-txt class more as the space is too constrained
-> then can implement archiving too
* per file you could select an unknown face and add it as a ref img to an existing person, or make a new person and attach?

View File

@@ -190,4 +190,14 @@
<text style="fill: rgb(13, 202, 240); font-family: Arial, sans-serif; font-size: 96px; font-weight: 700; white-space: pre;" x="20.59" y="133.396">270</text>
</g>
</svg>
<svg id="sort-num-asc" viewBox="0 0 16 16">
<path d="M12.438 1.668V7H11.39V2.684h-.051l-1.211.859v-.969l1.262-.906h1.046z"/>
<path fill-rule="evenodd" d="M11.36 14.098c-1.137 0-1.708-.657-1.762-1.278h1.004c.058.223.343.45.773.45.824 0 1.164-.829 1.133-1.856h-.059c-.148.39-.57.742-1.261.742-.91 0-1.72-.613-1.72-1.758 0-1.148.848-1.835 1.973-1.835 1.09 0 2.063.636 2.063 2.687 0 1.867-.723 2.848-2.145 2.848zm.062-2.735c.504 0 .933-.336.933-.972 0-.633-.398-1.008-.94-1.008-.52 0-.927.375-.927 1 0 .64.418.98.934.98z"/>
<path d="M4.5 2.5a.5.5 0 0 0-1 0v9.793l-1.146-1.147a.5.5 0 0 0-.708.708l2 1.999.007.007a.497.497 0 0 0 .7-.006l2-2a.5.5 0 0 0-.707-.708L4.5 12.293V2.5z"/>
</svg>
<svg id="sort-num-desc" viewBox="0 0 16 16">
<path d="M12.438 1.668V7H11.39V2.684h-.051l-1.211.859v-.969l1.262-.906h1.046z"/>
<path fill-rule="evenodd" d="M11.36 14.098c-1.137 0-1.708-.657-1.762-1.278h1.004c.058.223.343.45.773.45.824 0 1.164-.829 1.133-1.856h-.059c-.148.39-.57.742-1.261.742-.91 0-1.72-.613-1.72-1.758 0-1.148.848-1.835 1.973-1.835 1.09 0 2.063.636 2.063 2.687 0 1.867-.723 2.848-2.145 2.848zm.062-2.735c.504 0 .933-.336.933-.972 0-.633-.398-1.008-.94-1.008-.52 0-.927.375-.927 1 0 .64.418.98.934.98z"/>
<path d="M4.5 13.5a.5.5 0 0 1-1 0V3.707L2.354 4.854a.5.5 0 1 1-.708-.708l2-1.999.007-.007a.498.498 0 0 1 .7.006l2 2a.5.5 0 1 1-.707.708L4.5 3.707V13.5z"/>
</svg>
</svg>

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 24 KiB

22
job.py
View File

@@ -9,7 +9,7 @@ from datetime import datetime, timedelta
from flask_login import login_required, current_user
import pytz
import socket
from shared import PA_JOB_MANAGER_HOST, PA_JOB_MANAGER_PORT
from shared import PA_JOB_MANAGER_HOST, PA_JOB_MANAGER_PORT, NEWEST_LOG_LIMIT, OLDEST_LOG_LIMIT
from flask_login import login_required, current_user
# pylint: disable=no-member
@@ -119,15 +119,23 @@ def jobs():
@app.route("/job/<id>", methods=["GET","POST"])
@login_required
def joblog(id):
page_title='Show Job Details'
joblog = Job.query.get(id)
log_cnt = db.session.execute( f"select count(id) from joblog where job_id = {id}" ).first()[0]
first_logs_only = True
if request.method == 'POST':
logs=Joblog.query.filter(Joblog.job_id==id).order_by(Joblog.log_date).all()
first_logs_only = False
display_more=False
order="asc"
else:
logs=Joblog.query.filter(Joblog.job_id==id).order_by(Joblog.log_date).limit(50).all()
log_cnt = db.session.execute( f"select count(id) from joblog where job_id = {id}" ).first()[0]
newest_logs = Joblog.query.filter(Joblog.job_id==id).order_by(Joblog.log_date.desc() ).limit(NEWEST_LOG_LIMIT).all()
oldest_logs = Joblog.query.filter(Joblog.job_id==id).order_by(Joblog.log_date).limit(OLDEST_LOG_LIMIT).all()
logs=sorted( set( newest_logs + oldest_logs ), key=lambda el: el.log_date, reverse=True)
if log_cnt > (NEWEST_LOG_LIMIT+OLDEST_LOG_LIMIT):
display_more=True
else:
display_more=False
order="desc"
if joblog.pa_job_state == "Completed":
duration=(joblog.last_update-joblog.start_time)
else:
@@ -140,7 +148,7 @@ def joblog(id):
estimate_s = duration_s / joblog.current_file_num * joblog.num_files
estimate = timedelta( seconds=(estimate_s-duration_s) )
estimate = estimate - timedelta(microseconds=estimate.microseconds)
return render_template("joblog.html", job=joblog, logs=logs, log_cnt=log_cnt, duration=duration, page_title=page_title, first_logs_only=first_logs_only, estimate=estimate)
return render_template("joblog.html", job=joblog, logs=logs, duration=duration, display_more=display_more, order=order, estimate=estimate)
###############################################################################
# /wakeup -> GET -> forces the job manager to wake up, and check the queue

View File

@@ -10,7 +10,7 @@ import os
import re
import socket
from status import st, Status
from shared import CreateSelect, CreateFoldersSelect, LocationIcon, DB_URL, PROD_HOST
from shared import CreateSelect, CreateFoldersSelect, LocationIcon, DB_URL, PROD_HOST, NEWEST_LOG_LIMIT
# for ldap auth
from flask_ldap3_login import LDAP3LoginManager
@@ -72,6 +72,7 @@ app.jinja_env.globals['ClearJM_Message'] = ClearJM_Message
app.jinja_env.globals['CreateSelect'] = CreateSelect
app.jinja_env.globals['CreateFoldersSelect'] = CreateFoldersSelect
app.jinja_env.globals['LocationIcon'] = LocationIcon
app.jinja_env.globals['NEWEST_LOG_LIMIT'] = NEWEST_LOG_LIMIT
# Declare a User Loader for Flask-Login.

View File

@@ -24,6 +24,8 @@ ICON["Storage"]="db"
ICON["Bin"]="trash"
SECS_IN_A_DAY = 86400
NEWEST_LOG_LIMIT = 5
OLDEST_LOG_LIMIT = 5
# check where we are running, if laptop, then run web server and db on localhost
if hostname == "lappy":

View File

@@ -2,7 +2,7 @@
{% block main_content %}
<div class="container-fluid">
<h3>{{page_title}}</h3>
<h3>Show Job Details</h3>
<dl class="row">
<dt class="col-2">Job #:</dt>
<dd class="col-10">{{job.id}}</dt>
@@ -46,13 +46,16 @@
<dd class="col-10">N/A</dd>
{% endif %}
</dl>
<table id="jobort_tbl" class="table table-striped table-sm" data-toolbar="#toolbar" data-search="true">
<thead><tr class="table-primary"><th>When</th><th>Details</th></tr></thead>
<thead><tr class="table-primary"><th>When
<svg width="16" height="16" fill="currentColor"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#sort-num-{{order}}"/></svg>
</th><th>Details</th></tr></thead>
<tbody>
{% for log in logs %}
<tr><td>{{log.log_date|vicdate}}</td><td>{{log.log|safe}}</td></tr>
{% endfor %}
{% if log_cnt > logs|length %}
{% if display_more and loop.index == NEWEST_LOG_LIMIT %}
<tr>
<td class="align-middle">Remaining logs truncated</td>
<td>
@@ -60,13 +63,14 @@
</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
</div class="containter">
{% endblock main_content %}
{% block script_content %}
<script>
{% if first_logs_only and job.pa_job_state != "Completed" %}
{% if display_more and job.pa_job_state != "Completed" %}
setTimeout(function(){ window.location.reload(1); }, 3000 )
{% endif %}
</script>