Skip to content

Commit

Permalink
Request search loop overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
Feramance committed Dec 5, 2024
1 parent 9547f46 commit c2d77b7
Showing 1 changed file with 49 additions and 8 deletions.
57 changes: 49 additions & 8 deletions qBitrr/arss.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,11 @@ def __init__(
if not isinstance(self.temp_quality_profiles, list):
self.temp_quality_profiles = [self.temp_quality_profiles]

self.use_temp_for_missing = CONFIG.get(
f"{name}.EntrySearch.UseTempForMissing", fallback=False
) and self.main_quality_profiles and self.temp_quality_profiles
self.use_temp_for_missing = (
CONFIG.get(f"{name}.EntrySearch.UseTempForMissing", fallback=False)
and self.main_quality_profiles
and self.temp_quality_profiles
)

if self.use_temp_for_missing:
self.temp_quality_profile_ids = self.parse_quality_profiles()
Expand Down Expand Up @@ -4707,15 +4709,54 @@ def run_request_search(self):
return None
self.logger.notice("Starting Request search")

totcommands = -1
searched = False
while True:
if self.loop_completed:
totcommands = -1
searched = False
try:
self.db_request_update()
try:
for entry in self.db_get_request_files():
while not self.maybe_do_search(entry, request=True):
time.sleep(30)
self.request_search_timer = time.time()
return
if datetime.now() >= (
self.request_search_timer + self.search_requests_every_x_seconds
):
self.refresh_download_queue()
raise RestartLoopException
if not searched:
for entry, commands in self.db_get_request_files():
if totcommands == -1:
totcommands = commands
self.logger.info("Starting search for %s items", totcommands)
if SEARCH_LOOP_DELAY == -1:
loop_delay = 30
else:
loop_delay = SEARCH_LOOP_DELAY
while not self.maybe_do_search(
entry,
request=True,
commands=totcommands,
):
self.logger.debug("Waiting for active search commands")
time.sleep(loop_delay)
if SEARCH_LOOP_DELAY != -1:
self.logger.info(
"Delaying search loop by %s seconds", SEARCH_LOOP_DELAY
)
time.sleep(SEARCH_LOOP_DELAY)
totcommands -= 1
if totcommands == 0:
self.logger.info("All searches completed")
searched = True
elif datetime.now() >= (
self.request_search_timer + self.search_requests_every_x_seconds
):
self.request_search_timer = time.time()
self.logger.info(
"Searches not completed, %s remaining", totcommands
)
while not self.maybe_do_search(entry, request=True):
time.sleep(30)
except NoConnectionrException as e:
self.logger.error(e.message)
raise DelayLoopException(length=300, type=e.type)
Expand Down

0 comments on commit c2d77b7

Please sign in to comment.