Skip to content

Commit f022675

Browse files
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...
1 parent 5714eeb commit f022675

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

sabnzbd/video.bash

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
scriptVersion="1.6"
2+
scriptVersion="1.7"
33
scriptName="Video"
44

55
#### Import Settings
@@ -126,16 +126,18 @@ ArrWaitForTaskCompletion () {
126126
alerted=no
127127
until false
128128
do
129-
taskCount=$(curl -s "$arrUrl/api/v3/command?apikey=${arrApiKey}" | jq -r '.[] | select(.status=="started") | .name' | wc -l)
130-
if [ "$taskCount" -ge "1" ]; then
131-
if [ "$alerted" == "no" ]; then
132-
alerted=yes
133-
log "$count of $fileCount :: STATUS :: ARR APP BUSY :: Pausing/waiting for all active Arr app tasks to end..."
134-
fi
135-
sleep 2
136-
else
137-
break
138-
fi
129+
arrtasks=$(curl -s "$arrUrl/api/v3/command?apikey=${arrApiKey}" | jq -r '.[] | select(.status=="started") | .name')
130+
taskCount=$(echo $arrtasks | wc -l)
131+
arrProcessMonitoredDownloadsCount=$(echo $arrtasks | grep "ProcessMonitoredDownloads" | wc -l)
132+
if [ "$taskCount" -ge 3 ] || [ "$arrProcessMonitoredDownloadsCount" -ge 1 ]; then
133+
if [ "$alerted" == "no" ]; then
134+
alerted=yes
135+
log "$count of $fileCount :: STATUS :: ARR APP BUSY :: Pausing/waiting for all active Arr app tasks to end..."
136+
fi
137+
sleep 2
138+
else
139+
break
140+
fi
139141
done
140142
}
141143

@@ -170,8 +172,8 @@ VideoSmaProcess (){
170172
arrApiKey="$radarrArrApiKey"
171173
fi
172174
log "$count of $fileCount :: Refreshing Radarr app Queue"
173-
#refreshQueue=$(curl -s "$arrUrl/api/v3/command" -X POST -H 'Content-Type: application/json' -H "X-Api-Key: $arrApiKey" --data-raw '{"name":"RefreshMonitoredDownloads"}')
174-
# ArrWaitForTaskCompletion
175+
refreshQueue=$(curl -s "$arrUrl/api/v3/command" -X POST -H 'Content-Type: application/json' -H "X-Api-Key: $arrApiKey" --data-raw '{"name":"RefreshMonitoredDownloads"}')
176+
ArrWaitForTaskCompletion
175177
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')
176178
arrItemData=$(curl -s "$arrUrl/api/v3/movie/$arrItemId?apikey=$arrApiKey")
177179
onlineSourceId="$(echo "$arrItemData" | jq -r ".tmdbId")"
@@ -188,8 +190,8 @@ VideoSmaProcess (){
188190
arrApiKey="$sonarrArrApiKey"
189191
fi
190192
log "$count of $fileCount :: Refreshing Sonarr app Queue"
191-
#refreshQueue=$(curl -s "$arrUrl/api/v3/command" -X POST -H 'Content-Type: application/json' -H "X-Api-Key: $arrApiKey" --data-raw '{"name":"RefreshMonitoredDownloads"}')
192-
# ArrWaitForTaskCompletion
193+
refreshQueue=$(curl -s "$arrUrl/api/v3/command" -X POST -H 'Content-Type: application/json' -H "X-Api-Key: $arrApiKey" --data-raw '{"name":"RefreshMonitoredDownloads"}')
194+
ArrWaitForTaskCompletion
193195
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)')
194196
arrSeriesId="$(echo $arrQueueItemData | jq -r .seriesId)"
195197
arrEpisodeId="$(echo $arrQueueItemData | jq -r .episodeId)"

0 commit comments

Comments
 (0)