pairofcrocs / qbit-unraid-slowdown

A script that interacts with the Plex server, qBittorrent, and an Unraid server to manage the speed of qBittorrent downloads based on the number of active streams on Plex and the status of a parity check operation on the Unraid server.
9 stars 2 forks source link

Refactored code using better practices and removed redundancy #3

Closed tmarkn closed 1 year ago

tmarkn commented 1 year ago
pairofcrocs commented 1 year ago

Thank you so much for these!

I'm by no means a good coder, so these PR are much appreciated :)

pairofcrocs commented 1 year ago

Actually, as long as I have you here.... A feature that I'd love to implement is checking the mover status/stopping and resuming as needed.

I've figured out the starting and stopping, that's easy enough, but I haven't found a elegant way to check if the mover is active. I could just start/stop the move automatically, but I'd love some logic in there to check it first.

Do you know of an easy way to check that?

tmarkn commented 1 year ago

After a bit of digging, there's no inherent way of checking the status of the mover as mover only has two commands start via mover and stop via mover stop. You can, however, check if the mover is running by using ps h `cat /var/run/mover.pid`. and will return cat: /var/run/mover.pid: No such file or directory if it's not running.

From here you can save the state and write it to file if it was running, stop it by executing mover stop. Then, start the mover again using mover if it was running (by reading the previous state in the file, then updating the state in file after starting the mover).

Another thing I found is that if you try to stop the mover using mover stop, it will tell you if it was running by returning either mover: not running or mover: stopped as the last line. When a new stream starts, you can attempt to execute this regardless and if the mover was stopped, you update the file to tell the mover to start again once all the streams have stopped. (see above)

As a side note, you can do the same thing with the parity check and without caring about the status of the parity check since the parity check will check for you regardless. parity.check pause will only pause if a parity check is running. Similarly, parity.check resume will only resume if it is paused.

tmarkn commented 1 year ago

Implemented in pull request #4