partial implementation of first_eid, last_eid -- I think the vals work -- they do for searches anyway, but not stored in pa_user_state yet

This commit is contained in:
2022-01-25 00:48:14 +11:00
parent 65ebfe2d31
commit 08ca9b4e74
7 changed files with 182 additions and 69 deletions

View File

@@ -720,7 +720,7 @@ def HandleJobs(first_run=False):
job.pa_job_state = 'Stale'
session.add(job)
AddLogForJob( job, "ERROR: Job has been marked stale as it did not complete" )
MessageToFE( job.id, "danger", f'Stale job, click&nbsp; <a href="javascript:document.body.innerHTML+=\'<form id=_fm method=POST action=/stale_jobs></form>\'; document.getElementById(\'_fm\').submit();">here</a>&nbsp;to restart or cancel' )
MessageToFE( job.id, "danger", f'Stale job, click&nbsp; <a href="javascript:document.body.innerHTML+=\'<form id=_fm method=GET action=/stale_jobs></form>\'; document.getElementById(\'_fm\').submit();">here</a>&nbsp;to restart or cancel' )
session.commit()
continue
if job.pa_job_state == 'New':
@@ -1258,6 +1258,38 @@ def WithdrawDependantJobs( job, id, reason ):
return
####################################################################################################################################
# next 3 funcs used to optimise whether to do dependant jobs (i.e. no new files, dont keep doing file details, ai scans
# find last successful importdir job for this path
####################################################################################################################################
def find_last_time_new_files_found(job):
path=[jex.value for jex in job.extra if jex.name == "path"][0]
jobs = session.execute( f"select j.* from job j, jobextra jex1, jobextra jex2 where j.id = jex1.job_id and j.id = jex2.job_id and jex1.name ='path' and jex1.value = '{path}' and jex2.name = 'new_files'")
for j in jobs:
return j.last_update.timestamp()
return 0
####################################################################################################################################
# find time of last getfiledetails job for this path
####################################################################################################################################
def find_last_successful_gfd_job(job):
path=[jex.value for jex in job.extra if jex.name == "path"][0]
jobs=session.query(Job).join(JobExtra).filter(Job.name=="getfiledetails").filter(JobExtra.value==path).filter(Job.state=='Completed').order_by(Job.id.desc()).limit(1).all()
for j in jobs:
return j.last_update.timestamp()
return 0
####################################################################################################################################
# find time of last run_ai_on_path job for this path
####################################################################################################################################
def find_last_successful_ai_scan(job):
path=[jex.value for jex in job.extra if jex.name == "path"][0]
jobs=session.query(Job).join(JobExtra).filter(Job.name=="run_ai_on_path").filter(JobExtra.value==path).filter(Job.state=='Completed').order_by(Job.id.desc()).limit(1).all()
for j in jobs:
return j.last_update.timestamp()
return 0
####################################################################################################################################
# JobImportDir(): job that scan import dir and processes entries in there - key function that uses os.walk() to traverse the
# file system and calls AddFile()/AddDir() as necessary
@@ -1352,16 +1384,28 @@ def JobImportDir(job):
job.current_file_num += len(subdirs)
dir.last_import_date = time.time()
job.num_files=overall_file_cnt
if found_new_files:
print("adding new_files jex" )
job.extra.append( JobExtra( name="new_files", value=found_new_files ) )
session.add(job)
rm_cnt=HandleAnyFSDeletions(job)
if found_new_files == 0:
last_scan=find_last_time_new_files_found(job)
last_file_details=find_last_successful_gfd_job(job)
last_ai_scan=find_last_successful_ai_scan(job)
print( f"last_scan={last_scan}" )
print( f"last_file_details={last_file_details}" )
print( f"last_ai_scan={last_ai_scan}" )
for j in session.query(Job).filter(Job.wait_for==job.id).all():
if j.name == "getfiledetails":
if j.name == "getfiledetails" and last_file_details > last_scan:
FinishJob(j, f"Job (#{j.id}) has been withdrawn -- #{job.id} (scan job) did not find new files", "Withdrawn" )
if j.name == "run_ai_on_path":
if j.name == "run_ai_on_path" and last_ai_scan > last_scan:
newest_refimg = session.query(Refimg).order_by(Refimg.created_on.desc()).limit(1).all()
if newest_refimg and orig_last_import >= newest_refimg[0].created_on:
if newest_refimg and last_scan >= newest_refimg[0].created_on:
FinishJob(j, f"Job (#{j.id}) has been withdrawn -- scan did not find new files, and no new reference images since last scan", "Withdrawn" )
FinishJob(job, f"Finished Importing: {path} - Processed {overall_file_cnt} files, Found {found_new_files} new files, Removed {rm_cnt} file(s)")
return