From f022675e660ae487ec20e9caabfa889f2e2dfc20 Mon Sep 17 00:00:00 2001 From: RandomNinjaAtk Date: Thu, 16 Jan 2025 15:21:37 -0500 Subject: [PATCH] v1.7 - Re-enable pausing for Arr app tasks to complete Improved the process of detecting whether Arr app is busy... It will now only pause if it detects 3 tasks are running, which is what each Arr app can handle. Or it will pause if the Arr app Process Monitored Downloads task is already running. This is to prevent over tasking the applications to allow them the cycles to complete a previous import... --- sabnzbd/video.bash | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/sabnzbd/video.bash b/sabnzbd/video.bash index 15fa8fe..f54762f 100644 --- a/sabnzbd/video.bash +++ b/sabnzbd/video.bash @@ -1,5 +1,5 @@ #!/bin/bash -scriptVersion="1.6" +scriptVersion="1.7" scriptName="Video" #### Import Settings @@ -126,16 +126,18 @@ ArrWaitForTaskCompletion () { alerted=no until false do - taskCount=$(curl -s "$arrUrl/api/v3/command?apikey=${arrApiKey}" | jq -r '.[] | select(.status=="started") | .name' | wc -l) - if [ "$taskCount" -ge "1" ]; then - if [ "$alerted" == "no" ]; then - alerted=yes - log "$count of $fileCount :: STATUS :: ARR APP BUSY :: Pausing/waiting for all active Arr app tasks to end..." - fi - sleep 2 - else - break - fi + arrtasks=$(curl -s "$arrUrl/api/v3/command?apikey=${arrApiKey}" | jq -r '.[] | select(.status=="started") | .name') + taskCount=$(echo $arrtasks | wc -l) + arrProcessMonitoredDownloadsCount=$(echo $arrtasks | grep "ProcessMonitoredDownloads" | wc -l) + if [ "$taskCount" -ge 3 ] || [ "$arrProcessMonitoredDownloadsCount" -ge 1 ]; then + if [ "$alerted" == "no" ]; then + alerted=yes + log "$count of $fileCount :: STATUS :: ARR APP BUSY :: Pausing/waiting for all active Arr app tasks to end..." + fi + sleep 2 + else + break + fi done } @@ -170,8 +172,8 @@ VideoSmaProcess (){ arrApiKey="$radarrArrApiKey" fi log "$count of $fileCount :: Refreshing Radarr app Queue" - #refreshQueue=$(curl -s "$arrUrl/api/v3/command" -X POST -H 'Content-Type: application/json' -H "X-Api-Key: $arrApiKey" --data-raw '{"name":"RefreshMonitoredDownloads"}') - # ArrWaitForTaskCompletion + refreshQueue=$(curl -s "$arrUrl/api/v3/command" -X POST -H 'Content-Type: application/json' -H "X-Api-Key: $arrApiKey" --data-raw '{"name":"RefreshMonitoredDownloads"}') + ArrWaitForTaskCompletion arrItemId=$(curl -s "$arrUrl/api/v3/queue?page=1&pageSize=50&sortDirection=ascending&sortKey=timeleft&includeUnknownMovieItems=true&apikey=$arrApiKey" | jq -r --arg id "$downloadId" '.records[] | select(.downloadId==$id) | .movieId') arrItemData=$(curl -s "$arrUrl/api/v3/movie/$arrItemId?apikey=$arrApiKey") onlineSourceId="$(echo "$arrItemData" | jq -r ".tmdbId")" @@ -188,8 +190,8 @@ VideoSmaProcess (){ arrApiKey="$sonarrArrApiKey" fi log "$count of $fileCount :: Refreshing Sonarr app Queue" - #refreshQueue=$(curl -s "$arrUrl/api/v3/command" -X POST -H 'Content-Type: application/json' -H "X-Api-Key: $arrApiKey" --data-raw '{"name":"RefreshMonitoredDownloads"}') - # ArrWaitForTaskCompletion + refreshQueue=$(curl -s "$arrUrl/api/v3/command" -X POST -H 'Content-Type: application/json' -H "X-Api-Key: $arrApiKey" --data-raw '{"name":"RefreshMonitoredDownloads"}') + ArrWaitForTaskCompletion arrQueueItemData=$(curl -s "$arrUrl/api/v3/queue?page=1&pageSize=50&sortDirection=ascending&sortKey=timeleft&includeUnknownSeriesItems=true&apikey=$arrApiKey" | jq -r --arg id "$downloadId" '.records[] | select(.downloadId==$id)') arrSeriesId="$(echo $arrQueueItemData | jq -r .seriesId)" arrEpisodeId="$(echo $arrQueueItemData | jq -r .episodeId)"