Browse Source

More advanced handling of slow responses

Zachary Kotlarek 12 years ago
parent
commit
6a23f60b16
1 changed files with 11 additions and 1 deletions
  1. 11 1
      pms/PMSCheck.sh

+ 11 - 1
pms/PMSCheck.sh

@@ -5,9 +5,9 @@ CURL_TIMEOUT=10
 RESTART_DELAY=300
 RESTART_DELAY=300
 PMS_URL="http://localhost:32400/"
 PMS_URL="http://localhost:32400/"
 UNWATCHED_SECTION="2"
 UNWATCHED_SECTION="2"
-UNWATCHED_TIMEOUT="${CURL_TIMEOUT}"
 UNWATCHED_SLEEP=60
 UNWATCHED_SLEEP=60
 UNWATCHED_RETRIES=5
 UNWATCHED_RETRIES=5
+UNWATCHED_TIMEOUT_FACTOR=2
 MIN_UNWATCHED_COUNT=10
 MIN_UNWATCHED_COUNT=10
 ADMIN_EMAIL="zach@kotlarek.com"
 ADMIN_EMAIL="zach@kotlarek.com"
 
 
@@ -48,6 +48,7 @@ while [ $LOOP -ne 0 ]; do
 	fi
 	fi
 
 
 	# Ask Plex for a list of unwatched TV series
 	# Ask Plex for a list of unwatched TV series
+	UNWATCHED_TIMEOUT=$(( $CURL_TIMEOUT * $UNWATCHED_TIMEOUT_FACTOR ))
 	if [ -z "${FAILED}" ]; then
 	if [ -z "${FAILED}" ]; then
 		UNWATCHED_URL="${PMS_URL}library/sections/${UNWATCHED_SECTION}/unwatched"
 		UNWATCHED_URL="${PMS_URL}library/sections/${UNWATCHED_SECTION}/unwatched"
 		TRY=1
 		TRY=1
@@ -61,6 +62,7 @@ while [ $LOOP -ne 0 ]; do
 			else
 			else
 				sleep $UNWATCHED_SLEEP
 				sleep $UNWATCHED_SLEEP
 				FAILED="${FAILED} ${COUNT}"
 				FAILED="${FAILED} ${COUNT}"
+				UNWATCHED_TIMEOUT=$(( $UNWATCHED_TIMEOUT + $(( $CURL_TIMEOUT * $UNWATCHED_TIMEOUT_FACTOR )) ))
 			fi
 			fi
 		done
 		done
 	fi
 	fi
@@ -80,6 +82,14 @@ while [ $LOOP -ne 0 ]; do
 		# Give plex a breather to get restarted before we check again
 		# Give plex a breather to get restarted before we check again
 		sleep "${RESTART_DELAY}"
 		sleep "${RESTART_DELAY}"
 
 
+		# Re-index (in the background)
+		~/bin/video/pms/optimize.sh &
+
+	# If Plex was super slow, optimize it
+	elif [ $UNWATCHED_TIMEOUT -gt $(( $CURL_TIMEOUT * $UNWATCHED_TIMEOUT_FACTOR * $(( $UNWATCHED_RETRIES / 2 )) )) ]; then
+		ERR_MSG="PMS is slow (${UNWATCHED_TIMEOUT}). Optimizing..."
+		echo "${ERR_MSG}" 1>&2
+
 		# Re-index (in the background)
 		# Re-index (in the background)
 		~/bin/video/pms/optimize.sh &
 		~/bin/video/pms/optimize.sh &
 	fi
 	fi