I was under the assumption that when Sonarr finishes downloading a season pack, it imports the files one at a time. Is that not the case? It seems that all episodes disappear from the queue all at once instead one at a time. I have a custom script that is runs on import but it seems that it only runs once instead of for each episode, or maybe the queue is just emptying too quickly. I’m trying to figure it out.
Each file is imported individually, but all items could be removed from the queue at the same time if completed download handling isn’t used for the import.
Hmmm. I double checked and completed download handling is enabled. My script is set to run on import but in the case of a season pack, it needs to wait until the last file is imported to run. The script has a conditional statement so that if there is more than one instance of the torrent hash in the queue, it exits the script without doing anything. The thinking was that it would import the files one at a time, each item getting removed from the queue one by one, and then execute on the last item. But the action in the script never gets executed, presumably because the queue always shows multiple items. It worked in testing however so I don’t think it’s an issue with the conditional logic. I tried looking at the logs but I don’t think I had logging turned up high enough and season packs only download every so often.
How was the file actually imported though? If you used the API to tell Sonarr to import that would not use Completed Download Handling.
I should clarify. I said on import but what I meant was on download and upgrade. It is a custom bash script, set in the “connect” tab in the settings and configured to run on download and upgrade. It uses the API to check the queue. If there is more than one item in the queue having the same value for downloadID (or whatever the property is that has the torrent hash) as the one passed to the script, then it exits the script without doing anything. This should indicate that there are still episodes in the season pack to import. Otherwise, it does something. It works for just single episodes, meaning the something gets done. But for season packs, that something doesn’t happen. I would expect that once completed download handling imports the last item in the season pack, all the other items would already be removed from the queue and the rest of the script should execute.
Completed Download Handling doesn’t remove anything from the queue until it completes it’s cycle (each episode isn’t removed as it’s imported). The custom script is called when the file imports, so other things to import would mean the queue isn’t accurate and it could also execute before the queue is updated, likely even (because of the processing that takes place after calling the script).
I forgot to mention, there is also a delay that I put at the start of the script. It waits for about a minute or two. I don’t remember why I put in the wait. It was a while ago. I just remember there were problems without it.
What does it mean to complete its cycle? What does that entail and how can I determine that programatically? I’m also don’t quite understand what you mean when you say other things to import would make the queue inaccurate.
Maybe there are things going on I’m missing or things aren’t happening in the order I thought. I thought that once Sonarr realizes the episode it done downloading (by polling the torrent client), it copies or hardlinks the files, updates the queue, and then executes the script.
That’ll just cause Sonarr to wait unless you’re forking to another PID.
The cycle of checking for items in the download client, processing them (failed or completed), it’s not until everything is processed that Sonarr updates the queue. The queue could be showing something at 100% downloaded and nothing more if it’s actively importing and hasn’t updated yet.
Maybe I put the delay because the torrent program was hash checking after complete. But then I don’t think that would show as complete to Sonarr. I don’t remember why I put in the delay, I just remember it didn’t work without it. I should have added a comment to my script.
Anyway, sorry, I’m still not following. Say I have one torrent with 5 episodes. 5 items appear in the Sonarr queue. The torrent completes and Sonarr starts doing the cycle you talked about. Are you saying all those items will appear as 100% until the last file is imported and THEN sonarr updates the queue? Maybe that’s what I’m getting confused about. I was thinking there would be 5 cycles, one for each item in the queue, but it sounds like there is one for each torrent.
Yes, correct. Taking it further if you had 5 different torrents for those same 5 episodes and they all were completed at the same time (so Sonarr processed them all at that time), then you’d see the same thing, they’d all be in the queue until the last file was imported because it’s part of the same cycle.
I’ve working on some changes to this behaviour that would avoid the individual files in individual torrents being handled that way, but a season pack wouldn’t change.
Ah ok, that makes sense. So basically, a cycle processes whichever torrents have completed since the last time Sonarr polled the download client, but the script is run on every episode that is imported.
Thanks, I shouldn’t have an issue now that I understand what I’m working with.