DEBUG is now a boolean to fix occasionaly debug when I did not want it

This commit is contained in:
2021-09-17 18:08:55 +10:00
parent 85902bbc3c
commit fe7627c89c

View File

@@ -15,7 +15,7 @@
# global debug setting # global debug setting
DEBUG=0 DEBUG=False
### SQLALCHEMY IMPORTS ### ### SQLALCHEMY IMPORTS ###
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
@@ -660,7 +660,7 @@ def FinishJob(job, last_log, state="Completed", pa_job_state="Completed"):
if job.state=="Failed": if job.state=="Failed":
CancelJob(job,job.id) CancelJob(job,job.id)
session.commit() session.commit()
if DEBUG==1: if DEBUG:
print( f"DEBUG: {last_log}" ) print( f"DEBUG: {last_log}" )
return return
@@ -669,7 +669,7 @@ def FinishJob(job, last_log, state="Completed", pa_job_state="Completed"):
# TODO: why not only retrieve New jobs from DB? # TODO: why not only retrieve New jobs from DB?
############################################################################## ##############################################################################
def HandleJobs(): def HandleJobs():
if DEBUG==1: if DEBUG:
print("INFO: PA job manager is scanning for new jobs to process") print("INFO: PA job manager is scanning for new jobs to process")
for job in session.query(Job).all(): for job in session.query(Job).all():
if job.pa_job_state == 'New': if job.pa_job_state == 'New':
@@ -684,7 +684,7 @@ def HandleJobs():
continue continue
# use this to remove threads for easier debugging, and errors will stacktrace to the console # use this to remove threads for easier debugging, and errors will stacktrace to the console
if DEBUG==1: if DEBUG:
print("*************************************") print("*************************************")
print("RUNNING job: id={} name={} wait_for={}".format(job.id, job.name, job.wait_for )) print("RUNNING job: id={} name={} wait_for={}".format(job.id, job.name, job.wait_for ))
RunJob(job) RunJob(job)
@@ -810,7 +810,7 @@ def AddDir(job, dirname, in_dir, rel_path, in_path ):
# no in_dir occurs when we Add the actual Dir for the Path (top of the tree) # no in_dir occurs when we Add the actual Dir for the Path (top of the tree)
if in_dir: if in_dir:
e.in_dir=in_dir e.in_dir=in_dir
if DEBUG==1: if DEBUG:
AddLogForJob(job, f"DEBUG: Process new dir: {dirname}, rel_path={rel_path}") AddLogForJob(job, f"DEBUG: Process new dir: {dirname}, rel_path={rel_path}")
session.add(e) session.add(e)
return dir return dir
@@ -1113,7 +1113,7 @@ def JobImportDir(job):
path=[jex.value for jex in job.extra if jex.name == "path"][0] path=[jex.value for jex in job.extra if jex.name == "path"][0]
path_type=[jex.value for jex in job.extra if jex.name == "path_type"][0] path_type=[jex.value for jex in job.extra if jex.name == "path_type"][0]
AddLogForJob(job, f"Checking {path_type} Directory: {path}" ) AddLogForJob(job, f"Checking {path_type} Directory: {path}" )
if DEBUG==1: if DEBUG:
print( f"DEBUG: Checking Directory: {path}" ) print( f"DEBUG: Checking Directory: {path}" )
if not os.path.exists( path ): if not os.path.exists( path ):
FinishJob( job, f"Finished Importing: {path} -- Path does not exist", "Failed" ) FinishJob( job, f"Finished Importing: {path} -- Path does not exist", "Failed" )
@@ -1167,7 +1167,7 @@ def JobImportDir(job):
stat = os.stat(fname) stat = os.stat(fname)
if stat.st_ctime > dir.last_import_date: if stat.st_ctime > dir.last_import_date:
if DEBUG==1: if DEBUG:
print("DEBUG: {} - {} is newer than {}".format( basename, stat.st_ctime, dir.last_import_date ) ) print("DEBUG: {} - {} is newer than {}".format( basename, stat.st_ctime, dir.last_import_date ) )
if isImage(fname): if isImage(fname):
type_str = 'Image' type_str = 'Image'
@@ -1180,7 +1180,7 @@ def JobImportDir(job):
year, month, day, woy = GetDateFromFile(fname, stat) year, month, day, woy = GetDateFromFile(fname, stat)
e=AddFile( job, basename, type_str, fsize, dir, year, month, day, woy ) e=AddFile( job, basename, type_str, fsize, dir, year, month, day, woy )
else: else:
if DEBUG==1: if DEBUG:
print( f"DEBUG: { basename} - {stat.st_ctime} is OLDER than {dir.last_import_date}" ) print( f"DEBUG: { basename} - {stat.st_ctime} is OLDER than {dir.last_import_date}" )
e=session.query(Entry).join(EntryDirLink).join(Dir).filter(Entry.name==basename,Dir.eid==dir.eid).first() e=session.query(Entry).join(EntryDirLink).join(Dir).filter(Entry.name==basename,Dir.eid==dir.eid).first()
e.exists_on_fs=True e.exists_on_fs=True
@@ -1305,7 +1305,7 @@ def GenHashAndThumb(job, e):
session.commit() session.commit()
stat = os.stat( e.FullPathOnFS() ) stat = os.stat( e.FullPathOnFS() )
if stat.st_ctime < e.file_details.last_hash_date: if stat.st_ctime < e.file_details.last_hash_date:
if DEBUG==1: if DEBUG:
print(f"OPTIM: GenHashAndThumb {e.name} file is older than last hash, skip this") print(f"OPTIM: GenHashAndThumb {e.name} file is older than last hash, skip this")
job.current_file_num+=1 job.current_file_num+=1
return return
@@ -1325,7 +1325,7 @@ def GenHashAndThumb(job, e):
# File, call file_func on it # File, call file_func on it
#################################################################################################################################### ####################################################################################################################################
def ProcessFilesInDir(job, e, file_func, count_dirs): def ProcessFilesInDir(job, e, file_func, count_dirs):
if DEBUG==1: if DEBUG:
print( f"DEBUG: ProcessFilesInDir: {e.FullPathOnFS()}") print( f"DEBUG: ProcessFilesInDir: {e.FullPathOnFS()}")
if e.type.name != 'Directory': if e.type.name != 'Directory':
file_func(job, e) file_func(job, e)
@@ -1345,7 +1345,7 @@ def JobGetFileDetails(job):
JobProgressState( job, "In Progress" ) JobProgressState( job, "In Progress" )
path=[jex.value for jex in job.extra if jex.name == "path"][0] path=[jex.value for jex in job.extra if jex.name == "path"][0]
path_prefix=[jex.value for jex in job.extra if jex.name == "path_prefix"][0] path_prefix=[jex.value for jex in job.extra if jex.name == "path_prefix"][0]
if DEBUG==1: if DEBUG:
print("DEBUG: JobGetFileDetails for path={path_prefix}" ) print("DEBUG: JobGetFileDetails for path={path_prefix}" )
p=session.query(Path).filter(Path.path_prefix==path_prefix).first() p=session.query(Path).filter(Path.path_prefix==path_prefix).first()
job.current_file_num = 0 job.current_file_num = 0