Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abort job if more than 50% of data is missing after trying x MB #1785

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions sabnzbd/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ def validate_script(value):
# Text values
rss_odd_titles = OptionList("misc", "rss_odd_titles", ["nzbindex.nl/", "nzbindex.com/", "nzbclub.com/"])
req_completion_rate = OptionNumber("misc", "req_completion_rate", 100.2, 100, 200)
missing_threshold_mbytes = OptionNumber("misc", "missing_threshold_mbytes", 0)
selftest_host = OptionStr("misc", "selftest_host", "self-test.sabnzbd.org")
movie_rename_limit = OptionStr("misc", "movie_rename_limit", "100M")
size_limit = OptionStr("misc", "size_limit", "0")
Expand Down
1 change: 1 addition & 0 deletions sabnzbd/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,7 @@ def saveSwitches(self, **kwargs):
"nomedia_marker",
"max_url_retries",
"req_completion_rate",
"missing_threshold_mbytes",
"wait_ext_drive",
"max_foldername_length",
"show_sysload",
Expand Down
2 changes: 1 addition & 1 deletion sabnzbd/nzbqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ def end_job(self, nzo: NzbObject):
if nzo.precheck:
nzo.save_to_disk()
# Check result
enough, _ = nzo.check_availability_ratio()
enough, _ = nzo.check_availability()
if enough:
# Enough data present, do real download
self.send_back(nzo)
Expand Down
16 changes: 12 additions & 4 deletions sabnzbd/nzbstuff.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
# SABnzbd modules
import sabnzbd
from sabnzbd.constants import (
MEBI,
GIGI,
ATTRIB_FILE,
JOB_ADMIN,
Expand Down Expand Up @@ -1188,7 +1189,7 @@ def remove_article(self, article: Article, success: bool):
# Check if we can succeed when we have missing articles
# Skip check if retry or first articles already deemed it hopeless
if not success and job_can_succeed and not self.reuse and cfg.fail_hopeless_jobs():
job_can_succeed, _ = self.check_availability_ratio()
job_can_succeed, _ = self.check_availability()

# Abort the job due to failure
if not job_can_succeed:
Expand Down Expand Up @@ -1472,20 +1473,22 @@ def abort_direct_unpacker(self):
if self.direct_unpacker:
self.direct_unpacker.abort()

def check_availability_ratio(self):
""" Determine if we are still meeting the required ratio """
def check_availability(self) -> Tuple[bool, float]:
""" Determine if we are still meeting the requirements for availability """
availability_ratio = req_ratio = cfg.req_completion_rate()
missing_threshold = cfg.missing_threshold_mbytes() * MEBI

# Rare case where the NZB only consists of par2 files
if self.bytes > self.bytes_par2:
# Calculate ratio based on byte-statistics
availability_ratio = 100 * (self.bytes - self.bytes_missing) / (self.bytes - self.bytes_par2)

logging.debug(
"Availability ratio=%.2f, bad articles=%d, total bytes=%d, missing bytes=%d, par2 bytes=%d",
"Availability ratio=%.2f, bad articles=%d, total bytes=%d, bytes tried=%d, missing bytes=%d, par2 bytes=%d",
availability_ratio,
self.bad_articles,
self.bytes,
self.bytes_tried,
self.bytes_missing,
self.bytes_par2,
)
Expand All @@ -1495,6 +1498,10 @@ def check_availability_ratio(self):
if self.bad_articles <= MAX_BAD_ARTICLES:
return True, req_ratio

# Check specific MB threshold, if set
if missing_threshold and self.bytes_missing > self.bytes_downloaded and self.bytes_missing > missing_threshold:
return False, availability_ratio

# Check based on availability ratio
return availability_ratio >= req_ratio, availability_ratio

Expand All @@ -1505,6 +1512,7 @@ def check_first_article_availability(self):
# Ignore this check on retry
if not self.reuse:
# Ignore undamaged or small downloads
logging.debug("Firt articles=%d, bad articles=%d", self.bad_articles, self.first_articles_count)
if self.bad_articles and self.first_articles_count >= 10:
# We need a float-division, see if more than 80% is there
if self.bad_articles / self.first_articles_count >= 0.8:
Expand Down
2 changes: 1 addition & 1 deletion sabnzbd/postproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def process_job(nzo: NzbObject):
# if no files are present (except __admin__), fail the job
if all_ok and len(globber(workdir)) < 2:
if nzo.precheck:
_, ratio = nzo.check_availability_ratio()
_, ratio = nzo.check_availability()
emsg = T("Download might fail, only %s of required %s available") % (ratio, cfg.req_completion_rate())
else:
emsg = T("Download failed - Not on your server(s)")
Expand Down