Update filemonitor.py

This commit is contained in:
David Maisonave
2024-08-06 22:33:54 -04:00
parent a3fc74ae54
commit 5d7d4bc80d

View File

@@ -80,8 +80,10 @@ if plugin.DRY_RUN:
plugin.Trace(f"(SCAN_MODIFIED={SCAN_MODIFIED}) (SCAN_ON_ANY_EVENT={SCAN_ON_ANY_EVENT}) (RECURSIVE={RECURSIVE})") plugin.Trace(f"(SCAN_MODIFIED={SCAN_MODIFIED}) (SCAN_ON_ANY_EVENT={SCAN_ON_ANY_EVENT}) (RECURSIVE={RECURSIVE})")
StopLibraryMonitorWaitingInTaskQueue = False StopLibraryMonitorWaitingInTaskQueue = False
JobIdInTheQue = 0
def isJobWaitingToRun(): def isJobWaitingToRun():
global StopLibraryMonitorWaitingInTaskQueue global StopLibraryMonitorWaitingInTaskQueue
global JobIdInTheQue
i = 1 i = 1
while i < 999: while i < 999:
jobDetails = plugin.STASH_INTERFACE.find_job(i) jobDetails = plugin.STASH_INTERFACE.find_job(i)
@@ -90,12 +92,14 @@ def isJobWaitingToRun():
if jobDetails['status'] == "READY": if jobDetails['status'] == "READY":
if jobDetails['description'] == "Running plugin task: Stop Library Monitor": if jobDetails['description'] == "Running plugin task: Stop Library Monitor":
StopLibraryMonitorWaitingInTaskQueue = True StopLibraryMonitorWaitingInTaskQueue = True
return i JobIdInTheQue = i
return True
else: else:
plugin.Trace(f"Last job {i}") plugin.Trace(f"Last job {i}")
break break
i += 1 i += 1
return 0 JobIdInTheQue = 0
return False
if plugin.CALLED_AS_STASH_PLUGIN: if plugin.CALLED_AS_STASH_PLUGIN:
plugin.Trace(f"isJobWaitingToRun() = {isJobWaitingToRun()})") plugin.Trace(f"isJobWaitingToRun() = {isJobWaitingToRun()})")
@@ -193,20 +197,19 @@ def start_library_monitor():
TmpTargetPaths = [] TmpTargetPaths = []
with mutex: with mutex:
while not shouldUpdate: while not shouldUpdate:
if plugin.CALLED_AS_STASH_PLUGIN and isJobWaitingToRun():
plugin.Log(f"Another task (JobID={JobIdInTheQue}) is waiting on the queue. Will restart FileMonitor to allow other task to run.")
JobIsRunning = True
break
if shm_buffer[0] != CONTINUE_RUNNING_SIG:
plugin.Log(f"Breaking out of loop. (shm_buffer[0]={shm_buffer[0]})")
break
plugin.Trace("Wait start") plugin.Trace("Wait start")
if plugin.CALLED_AS_STASH_PLUGIN: if plugin.CALLED_AS_STASH_PLUGIN:
signal.wait(timeout=SIGNAL_TIMEOUT) signal.wait(timeout=SIGNAL_TIMEOUT)
else: else:
signal.wait() signal.wait()
plugin.Trace("Wait end") plugin.Trace("Wait end")
if shm_buffer[0] != CONTINUE_RUNNING_SIG:
plugin.Log(f"Breaking out of loop. (shm_buffer[0]={shm_buffer[0]})")
break
JobIdInTheQue = isJobWaitingToRun()
if plugin.CALLED_AS_STASH_PLUGIN and JobIdInTheQue:
plugin.Log(f"Another task (JobID={JobIdInTheQue}) is waiting on the queue. Will restart FileMonitor to allow other task to run.")
JobIsRunning = True
shouldUpdate = True
shouldUpdate = False shouldUpdate = False
TmpTargetPaths = [] TmpTargetPaths = []
for TargetPath in TargetPaths: for TargetPath in TargetPaths: