revamp whole EA flow. Server created EAs when we do certain jobs (transform, delete_files, restore_files), then instead of faking amendments in the jscript, get job creation to return EA from job ORM, then check is now generic for end of any amendment job, and when it finishes, use that to clear our amendments in document, and redraw through normal UI code. No smarts in client, all driven by state from server, and if we reload a page mid jobs, it has required state, and because an amendment job is still progressing, it runs check code again
This commit is contained in:
56
files.py
56
files.py
@@ -5,6 +5,7 @@ from main import db, app, ma
|
||||
from sqlalchemy import Sequence, text, select, union, or_
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import joinedload
|
||||
import numbers
|
||||
import os
|
||||
import glob
|
||||
import json
|
||||
@@ -266,6 +267,22 @@ class EntrySchema(ma.SQLAlchemyAutoSchema):
|
||||
def get_full_path(self, obj):
|
||||
return obj.FullPathOnFS()
|
||||
|
||||
class JobExtraSchema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta:
|
||||
model = JobExtra
|
||||
load_instance = True
|
||||
name = ma.auto_field()
|
||||
value = ma.auto_field()
|
||||
|
||||
class JobSchema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta:
|
||||
model = Job
|
||||
load_instance = True
|
||||
id = ma.auto_field()
|
||||
name = ma.auto_field()
|
||||
extra = ma.Nested(JobExtraSchema, many=True)
|
||||
amendments = ma.Nested(EntryAmendmentSchema, many=True)
|
||||
|
||||
# global - this will be use more than once below, so do it once for efficiency
|
||||
entries_schema = EntrySchema(many=True)
|
||||
FOT_Schema = FaceOverrideTypeSchema(many=True)
|
||||
@@ -273,6 +290,8 @@ path_Schema = PathSchema(many=True)
|
||||
person_Schema = PersonSchema(many=True)
|
||||
et_schema = AmendmentTypeSchema(many=True)
|
||||
ea_schema = EntryAmendmentSchema(many=True)
|
||||
job_schema = JobSchema(many=False)
|
||||
job_schemas = JobSchema(many=True)
|
||||
|
||||
################################################################################
|
||||
# /get_entries_by_ids -> route where we supply list of entry ids (for next/prev
|
||||
@@ -312,7 +331,7 @@ def process_ids():
|
||||
ea = db.session.execute(stmt).unique().scalars().all()
|
||||
ea_data=ea_schema.dump(ea)
|
||||
|
||||
return jsonify(entries=entries_schema.dump(sorted_data), amend=ea_data)
|
||||
return jsonify(entries=entries_schema.dump(sorted_data), amendments=ea_data)
|
||||
|
||||
|
||||
################################################################################
|
||||
@@ -629,7 +648,7 @@ def restore_files():
|
||||
jex.append( JobExtra( name=f"{el}", value=str(request.form[el]) ) )
|
||||
|
||||
job=NewJob( name="restore_files", num_files=0, wait_for=None, jex=jex, desc="to restore selected file(s)" )
|
||||
return redirect("/jobs")
|
||||
return jsonify( job=job_schema.dump(job) )
|
||||
|
||||
################################################################################
|
||||
# /delete_files -> create a job to delete files for the b/e to process
|
||||
@@ -642,7 +661,7 @@ def delete_files():
|
||||
jex.append( JobExtra( name=f"{el}", value=str(request.form[el]) ) )
|
||||
|
||||
job=NewJob( name="delete_files", num_files=0, wait_for=None, jex=jex, desc="to delete selected file(s)" )
|
||||
return redirect("/jobs")
|
||||
return jsonify( job=job_schema.dump(job) )
|
||||
|
||||
################################################################################
|
||||
# /move_files -> create a job to move files for the b/e to process
|
||||
@@ -685,7 +704,7 @@ def view():
|
||||
|
||||
# route called from front/end - if multiple images are being transformed, each transorm == a separate call
|
||||
# to this route (and therefore a separate transorm job. Each reponse allows the f/e to check the
|
||||
# specific transorm job is finished (/check_transform_job) which will be called (say) every 1 sec. from f/e
|
||||
# specific transorm job is finished (/check_amend_job_status) which will be called (say) every 1 sec. from f/e
|
||||
# with a spinning wheel, then when pa_job_mgr has finished it will return the transformed thumb
|
||||
@app.route("/transform", methods=["POST"])
|
||||
@login_required
|
||||
@@ -698,27 +717,28 @@ def transform():
|
||||
jex.append( JobExtra( name=f"{el}", value=str(request.form[el]) ) )
|
||||
|
||||
job=NewJob( name="transform_image", num_files=0, wait_for=None, jex=jex, desc="to transform selected file(s)" )
|
||||
return jsonify( job_id=job.id )
|
||||
return jsonify( job=job_schema.dump(job) )
|
||||
|
||||
################################################################################
|
||||
# /check_transform_job -> URL that is called repeatedly by front-end waiting for the
|
||||
# b/e to finish the transform job. Once done, the new / now
|
||||
# transformed image's thumbnail is returned so the f/e can
|
||||
# update with it
|
||||
# /check_amend_job_status -> URL that is called repeatedly by front-end waiting
|
||||
# for the b/e to finish the amendment job (delete/restore/move file).
|
||||
# Once done, return "ok"
|
||||
################################################################################
|
||||
@app.route("/check_transform_job", methods=["POST"])
|
||||
@app.route("/check_amend_job_status", methods=["POST"])
|
||||
@login_required
|
||||
def check_transform_job():
|
||||
def check_amend_job_status():
|
||||
job_id = request.form['job_id']
|
||||
stmt=select(Job).where(Job.id==job_id)
|
||||
job=db.session.execute(stmt).scalars().one_or_none()
|
||||
j=jsonify( finished=False )
|
||||
if job.pa_job_state == 'Completed':
|
||||
id=[jex.value for jex in job.extra if jex.name == "id"][0]
|
||||
stmt=select(Entry).where(Entry.id==id)
|
||||
stmt = select(Job).options(joinedload(Job.amendments)).where(Job.id == job_id)
|
||||
job=db.session.execute(stmt).unique().scalars().first()
|
||||
# FIXME: should validate job_id is real from UI
|
||||
if job.name == 'transform_image':
|
||||
eid=[jex.value for jex in job.extra if jex.name == "id"][0]
|
||||
stmt=select(Entry).where(Entry.id==eid)
|
||||
ent=db.session.execute(stmt).scalars().all()
|
||||
ent_data=entries_schema.dump(ent)
|
||||
j=jsonify( finished=True, entry=ent_data[0] )
|
||||
j=jsonify(finished=(job.pa_job_state == 'Completed'), job=job_schema.dump(job), entry=ent_data[0] )
|
||||
else:
|
||||
j=jsonify(finished=(job.pa_job_state == 'Completed'), job=job_schema.dump(job))
|
||||
return j
|
||||
|
||||
################################################################################
|
||||
|
||||
Reference in New Issue
Block a user