ckcr4lyf / qbit-race

Qbittorrent utilities for racing
120 stars 8 forks source link

qbit-race tries to reannounce before torrent is added, causing failure #50

Closed ckcr4lyf closed 1 month ago

ckcr4lyf commented 1 month ago

Currently, the sleep time between calling the addTorrent API and getting the tracker list is hardcoded as 5 seconds:

https://github.com/ckcr4lyf/qbit-race/blob/f337e03abcf842d1eb03578e7d5b3f14e02147d0/src/racing/add.ts#L75-L77

However, on some slower seedboxes/ disks / whatever, this may take longer.

E.g., qbit-race logs:

[2024-07-24T07:44:51Z DEBUG snatcher::action] Added to qbittorrent: 2024-07-24T07:44:46.013Z [DBG]: Config file exists. Will try reading it
    2024-07-24T07:44:46.017Z [INF]: Starting...
    2024-07-24T07:44:46.021Z [DBG]: Going to add torrent from /tmp/REDACTED.torrent, and set category undefined
    2024-07-24T07:44:46.202Z [DBG]: Called with path: /tmp/REDACTED.torrent, category: undefined
    2024-07-24T07:44:46.211Z [DBG]: Currently 0 stalled downloading torrents
    2024-07-24T07:44:46.212Z [DBG]: Going to pause 0 torrents for the race...
    2024-07-24T07:44:51.230Z [ERR]: Failed to get tags for torrent: Error: Failed to get trackers from qBittorrent API for c1892b3ed81b12248f17a98e367cc25c3736d6f0. Error: AxiosError: Request failed with status code 404

And qbittorrent logs:

(N) 2024-07-24T07:44:46 - WebAPI login success. IP: 127.0.0.1
(N) 2024-07-24T07:44:53 - 'REDACTED added to download list.

^ Where the first login at 07:44:46 is from qbit-race authenticating, however the torrent only got registered at 07:44:53. Due to the hardcoded 5s, it errored out.

ckcr4lyf commented 1 month ago

Proposed Fix

After the initial sleep of 5 seconds, we could poll the API every n seconds upto a total of m times till it is registered.

ckcr4lyf commented 1 month ago

Fixed in #51