diff --git a/plugins/FileMonitor/filemonitor.py b/plugins/FileMonitor/filemonitor.py index 3f0a4e2..f0d6910 100644 --- a/plugins/FileMonitor/filemonitor.py +++ b/plugins/FileMonitor/filemonitor.py @@ -407,8 +407,10 @@ lastScanJob = { "TargetPaths": [], "DelayedProcessTargetPaths": [], "timeAddedToTaskQueue": None, + "timeOutDelayProcess": 1, "lastStatus" : "" } +JOB_ENDED_STATUSES = ["FINISHED", "CANCELLED"] def start_library_monitor(): global shouldUpdate @@ -541,8 +543,12 @@ def start_library_monitor(): if stash.pluginSettings['turnOnScheduler']: stashScheduler.checkSchedulePending() timeOutInSeconds = SIGNAL_TIMEOUT - if lastScanJob['DelayedProcessTargetPaths'] != [] and timeOutInSeconds > MAX_TIMEOUT_FOR_DELAY_PATH_PROCESS: - timeOutInSeconds = MAX_TIMEOUT_FOR_DELAY_PATH_PROCESS + if lastScanJob['DelayedProcessTargetPaths'] != [] and timeOutInSeconds > lastScanJob['timeOutDelayProcess']: + if lastScanJob['timeOutDelayProcess'] < MAX_TIMEOUT_FOR_DELAY_PATH_PROCESS: + lastScanJob['timeOutDelayProcess'] = lastScanJob['timeOutDelayProcess'] * 2 + if lastScanJob['timeOutDelayProcess'] > MAX_TIMEOUT_FOR_DELAY_PATH_PROCESS: + lastScanJob['timeOutDelayProcess'] = MAX_TIMEOUT_FOR_DELAY_PATH_PROCESS + timeOutInSeconds = lastScanJob['timeOutDelayProcess'] stash.LogOnce(f"Awaiting file change-trigger, with a short timeout ({timeOutInSeconds} seconds), because of active delay path processing.") else: stash.LogOnce(f"Waiting for a file change-trigger. Timeout = {timeOutInSeconds} seconds.") @@ -585,10 +591,11 @@ def start_library_monitor(): stash.Warn(f"Could not get a status from scan job {lastScanJob['id']}; result = {lastScanJob['lastStatus']}; Elapse-Time = {elapsedTime}") else: stash.Trace(f"Last Scan Job ({lastScanJob['id']}); Status = {lastScanJob['lastStatus']['status']}; result = {lastScanJob['lastStatus']}; Elapse-Time = {elapsedTime}") - if 'status' not in lastScanJob['lastStatus'] or lastScanJob['lastStatus']['status'] == "FINISHED" or elapsedTime > MAX_SECONDS_WAIT_SCANJOB_COMPLETE: + if 'status' not in lastScanJob['lastStatus'] or lastScanJob['lastStatus']['status'] in JOB_ENDED_STATUSES or elapsedTime > MAX_SECONDS_WAIT_SCANJOB_COMPLETE: if elapsedTime > MAX_SECONDS_WAIT_SCANJOB_COMPLETE: stash.Warn(f"Timeout occurred waiting for scan job {lastScanJob['id']} to complete. Elapse-Time = {elapsedTime}; Max-Time={MAX_SECONDS_WAIT_SCANJOB_COMPLETE}; Scan-Path(s) = {lastScanJob['TargetPaths']}") lastScanJob['id'] = -1 + lastScanJob['timeOutDelayProcess'] = 1 if len(lastScanJob['DelayedProcessTargetPaths']) > 0: stash.Trace(f"Adding {lastScanJob['DelayedProcessTargetPaths']} to {TmpTargetPaths}") for path in lastScanJob['DelayedProcessTargetPaths']: diff --git a/plugins/FileMonitor/filemonitor_config.py b/plugins/FileMonitor/filemonitor_config.py index e1aacea..38ed73a 100644 --- a/plugins/FileMonitor/filemonitor_config.py +++ b/plugins/FileMonitor/filemonitor_config.py @@ -47,7 +47,7 @@ config = { # Timeout in seconds. This is how often FileMonitor will check the scheduler and (in-plugin mode) check if another job (Task) is in the queue. "timeOut": 60, # Timeout in seconds for delay processing of path scan jobs. This value should always be smaller than timeOut - "timeOutDelayProcess": 3, + "timeOutDelayProcess": 32, # Maximum time to wait for a scan job to complete. Need this incase Stash gets restarted in the middle of a scan job. "maxWaitTimeJobFinish": 30 * 60, # Wait 30 minutes max