From 8a6a7a51155508131a582fe5ce03a93fd695145a Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Thu, 13 Jan 2022 21:12:09 +1100 Subject: [PATCH] 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. --- TODO | 3 +++ internal/icons.svg | 10 ++++++++++ job.py | 22 +++++++++++++++------- main.py | 3 ++- shared.py | 2 ++ templates/joblog.html | 26 +++++++++++++++----------- 6 files changed, 47 insertions(+), 19 deletions(-) diff --git a/TODO b/TODO index 5906013..ff61c60 100644 --- a/TODO +++ b/TODO @@ -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, , 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? diff --git a/internal/icons.svg b/internal/icons.svg index dbac8a5..a463aa5 100644 --- a/internal/icons.svg +++ b/internal/icons.svg @@ -190,4 +190,14 @@ 270 + + + + + + + + + + diff --git a/job.py b/job.py index 2a895e2..8c16c60 100644 --- a/job.py +++ b/job.py @@ -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/", 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 diff --git a/main.py b/main.py index 8098406..56f0f8f 100644 --- a/main.py +++ b/main.py @@ -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. diff --git a/shared.py b/shared.py index b1f14b6..46cecfe 100644 --- a/shared.py +++ b/shared.py @@ -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": diff --git a/templates/joblog.html b/templates/joblog.html index 5dd0c83..17d485b 100644 --- a/templates/joblog.html +++ b/templates/joblog.html @@ -2,7 +2,7 @@ {% block main_content %}
-

{{page_title}}

+

Show Job Details

Job #:
{{job.id}} @@ -46,27 +46,31 @@
N/A
{% endif %}
+ + - + {% for log in logs %} + {% if display_more and loop.index == NEWEST_LOG_LIMIT %} + + + + + {% endif %} {% endfor %} - {% if log_cnt > logs|length %} - - - - - {% endif %}
WhenDetails
When + + Details
{{log.log_date|vicdate}}{{log.log|safe}}
Remaining logs truncated + +
Remaining logs truncated - -
{% endblock main_content %} {% block script_content %}