From 83eff0291055c8c49dcb00ac33da09943864fd33 Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Sat, 5 Feb 2022 23:23:10 +1100 Subject: [PATCH] added plumbing for viewer to have a joblog search for the current file --- TODO | 3 +++ job.py | 37 +++++++++++++++++++++++++++++++++++-- templates/viewer.html | 10 ++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 608229e..427fe74 100644 --- a/TODO +++ b/TODO @@ -2,6 +2,9 @@ * on viewer: - allow face to be used to create person, add to existing person, and allow 'ignore', mark as 'not a face', etc -> ignore/not a face/too young --> all need to go into DB so we can remember the 'override' when we re-ai-match + -> redraw 'ignore's as a greyed out box? + -> menu should only allow override IF we have put override on... + SO, override manual match, is awkward if somehow the file/face changes (e.g. we rescan a file for faces, do I delete override? if not and we rescan, there will he a new face id, how do I know which it connects with????) - allow joblog search from the viewer for that file... * should allow right-click from View menu (particularly useful on search) to show other files around this one by date (maybe that folder or something?) diff --git a/job.py b/job.py index c1d0e78..fa50983 100644 --- a/job.py +++ b/job.py @@ -79,7 +79,6 @@ def GetNumActiveJobs(): ################################################################################ def WakePAJobManager(): try: - print("Waking up PA Job Manager") s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((PA_JOB_MANAGER_HOST, PA_JOB_MANAGER_PORT)) s.close() @@ -175,7 +174,6 @@ def wakeup(): @app.route("/stale_job/", methods=["POST"]) @login_required def stale_job(id): - print( f"Handle Stale Job#{id} -> {request.form['action']} it") job=Job.query.get(id) now=datetime.now(pytz.utc) db.session.add(job) @@ -199,6 +197,8 @@ def stale_job(id): WakePAJobManager() return redirect("/jobs") +################################################################################ +# list jobs that are maked stale ################################################################################ @app.route("/stale_jobs", methods=["GET"]) @login_required @@ -207,6 +207,39 @@ def stale_jobs(): jobs = Job.query.filter(Job.pa_job_state=='Stale').order_by(Job.id.desc()).all() return render_template("jobs.html", jobs=jobs, page_title=page_title) + +################################################################################ +# retrieve any log entries across ALL jobs that relate to this entry +# used in viewer on button click +################################################################################ +@app.route("/joblog_search", methods=["POST"]) +@login_required +def joblog_search(): + eid=request.form['eid'] + ent_cursor=db.engine.execute( f"select name from entry where id = {eid}" ) + for ent in ent_cursor: + jobs_cursor=db.engine.execute( f"select l.log, j.id, j.name, j.state, j.last_update from joblog l, job j where l.job_id = j.id and l.log ilike '%%{ent[0]}%%' ") + + # turn DB output into json and return it to the f/e + ret='[ ' + first_job=1 + last_job_id = -1 + for j in jobs_cursor: + if not first_job: + ret +=", " + ret+= '{' + ret+= f'"id":"{j.id}", ' + ret+= f'"name":"{j.name}", ' + ret+= f'"finished":"{j.last_update}", ' + ret+= f'"status":"{j.state}", ' + ret+= f'"log": "{j.log}"' + ret+= '}' + first_job=0 + ret+= ' ]' + return ret + + + ############################################################################### # This func creates a new filter in jinja2 to format the time from the db in a # way that is more readable (converted to local tz too) diff --git a/templates/viewer.html b/templates/viewer.html index 58c7add..9a0e397 100644 --- a/templates/viewer.html +++ b/templates/viewer.html @@ -75,6 +75,16 @@ return s } + function JoblogSearch() + { + data="eid="+current + $.ajax({ type: 'POST', data: data, url: '/joblog_search', success: function(res) { + data = JSON.parse(res) + console.log(data) + } + }) + } + function CallViewListRoute(dir) { data="eids="+$("#eids").val()