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

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