nebhead / PlexPostProc

Plex PostProcessing Script for DVR(Beta)
77 stars 30 forks source link

ppplock file issue #23

Closed apassiou closed 2 years ago

apassiou commented 2 years ago

Script works (however I heavily customized ffmpeg string for my own needs, such as downconverting to stereo, AAC 112kbps and lowering framerate from 60 to 24 in order to save space).

However looking at the workaround function, mine was stuck in forever waiting loop waiting for .ppplock files to go away. I dont know how or why I had some in the directory (there was zero activity on Plex) but script only finished when I manually deleted them via ssh.

I modified this block in 2 ways:

1) increased check time to 60 seconds from 5, as to not spam the log. 2) added a timeout, where after 2 hours it will give up and proceed to the end of the script. I figure 2 hours is more than enough for whatever created ppplock legitimately to be done. And I want to avoid a situation where my DVR recordings never show up because the conversion script is stuck.

  # [WORKAROUND] Wait for any other post-processing scripts to complete before exiting.
   timeout_counter=120
   while [ true ] ; do
     if ls "$TMPFOLDER/"*".ppplock" 1> /dev/null 2>&1; then
       if  [[ $timeout_counter -eq 0 ]]; then
           echo "Timeout reached, ending wait" | tee -a $LOGFILE
           break
       fi
       echo "$(date +"%Y%m%d-%H%M%S"): Looks like there is another scripting running.  Waiting." | tee -a $LOGFILE
       timeout_counter=$((timeout_counter-1))
       sleep 60
     else
       echo "$(date +"%Y%m%d-%H%M%S"): It looks like all scripts are done running, exiting." | tee -a $LOGFILE
       break
     fi
   done
nebhead commented 2 years ago

FYI, if you want to raise a pull request for this part of the change, I will happily incorporate.