Redesign of retry for failed URL fetches.

Remove the clumsy embedded link in the error message.
Instead use the Retry for normal jobs.
Use the obsolete "report" field in the database to store the type of the job, "future" for failed fetches.
This commit is contained in:
shypike
2015-08-14 20:04:03 +02:00
parent 87949e25b3
commit 6eedd99deb
3 changed files with 42 additions and 34 deletions

View File

@@ -1547,11 +1547,16 @@ def retry_job(job, new_nzb, password):
""" Re enter failed job in the download queue """
if job:
history_db = cherrypy.thread_data.history_db
path = history_db.get_path(job)
if path:
nzo_id = repair_job(platform_encode(path), new_nzb, password)
futuretype, url, pp, script, cat = history_db.get_other(job)
if futuretype:
sabnzbd.add_url(url, pp, script, cat)
history_db.remove_history(job)
return nzo_id
else:
path = history_db.get_path(job)
if path:
nzo_id = repair_job(platform_encode(path), new_nzb, password)
history_db.remove_history(job)
return nzo_id
return None
@@ -1846,7 +1851,11 @@ def build_history(start=None, limit=None, verbose=False, verbose_list=None, sear
item['size'] = ''
if not item.has_key('loaded'):
item['loaded'] = False
path = platform_encode(item.get('path', ''))
if item.get('status') != 'Failed':
item['path'] = ''
item['retry'] = int(bool(item.get('status') == 'Failed' and \
path and \
path not in retry_folders and \
@@ -1854,6 +1863,9 @@ def build_history(start=None, limit=None, verbose=False, verbose_list=None, sear
os.path.exists(path)) and \
not bool(globber(os.path.join(path, JOB_ADMIN), 'SABnzbd_n*')) \
)
if item['report'] == 'future':
item['retry'] = True
if item['retry']:
retry_folders.append(path)

View File

@@ -367,6 +367,23 @@ class HistoryDB(object):
pass
return path
def get_other(self, nzo_id):
t = (nzo_id,)
if self.execute('SELECT * FROM history WHERE nzo_id=?', t):
try:
items = self.c.fetchall()[0]
dtype = items.get('report')
url = items.get('url')
pp = items.get('pp')
script = items.get('script')
cat = items.get('category')
except AttributeError:
return '', '', '', '', ''
return dtype, url, pp, script, cat
def dict_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
@@ -425,6 +442,9 @@ def build_history_info(nzo, storage='', downpath='', postproc_time=0, script_out
lines.append('%s:::%s' % (key, ';'.join(results)))
stage_log = '\r\n'.join(lines)
# Reuse the old 'report' column to indicate a URL-fetch
report = 'future' if nzo.futuretype else ''
# Analyse series info only when job is finished
series = u''
if postproc_time:
@@ -432,7 +452,7 @@ def build_history_info(nzo, storage='', downpath='', postproc_time=0, script_out
if seriesname and season and episode:
series = u'%s/%s/%s' % (seriesname.lower(), season, episode)
return (completed, name, nzb_name, category, pp, script, '', url, status, nzo_id, storage, path, \
return (completed, name, nzb_name, category, pp, script, report, url, status, nzo_id, storage, path, \
script_log, script_line, download_time, postproc_time, stage_log, downloaded, completeness, \
fail_message, url_info, bytes, series, nzo.md5sum)

View File

@@ -117,6 +117,9 @@ class URLGrabber(Thread):
if 'CERTIFICATE_VERIFY_FAILED' in error:
msg = T('Server %s uses an untrusted HTTPS certificate') % misc.get_urlbase(url)
retry = False
elif 'nodename nor servname provided' in error:
msg = T('Server name does not resolve')
retry = False
except:
logging.debug("Exception %s trying to get the url %s", sys.exc_info()[0], url)
@@ -306,25 +309,8 @@ def bad_fetch(nzo, url, msg='', retry=False, content=False):
else:
msg = ''
pp = nzo.pp
if pp is None:
pp = ''
else:
pp = '&pp=%s' % str(pp)
cat = nzo.cat
if cat:
cat = '&cat=%s' % urllib.quote(cat)
else:
cat = ''
script = nzo.script
if script:
script = '&script=%s' % urllib.quote(script)
else:
script = ''
nzo.status = Status.FAILED
if url:
nzo.filename = url
nzo.final_name = url.strip()
@@ -334,19 +320,9 @@ def bad_fetch(nzo, url, msg='', retry=False, content=False):
msg = T('Unusable NZB file')
else:
# Failed fetch
msg = ' (' + msg + ')'
msg = T('URL Fetching failed; %s') % msg
if retry:
nzbname = nzo.custom_name
if nzbname:
nzbname = '&nzbname=%s' % urllib.quote(nzbname)
else:
nzbname = ''
text = T('URL Fetching failed; %s') + ', <a href="./retry?session=%s&url=%s&job=%s%s%s%s%s">' + T('Try again') + '</a>'
parms = (msg, cfg.api_key(), urllib.quote(url), nzo.nzo_id, pp, cat, script, nzbname)
nzo.fail_msg = text % parms
else:
nzo.fail_msg = msg
nzo.fail_msg = msg
growler.send_notification(T('URL Fetching failed; %s') % '', '%s\n%s' % (msg, url), 'other')
if cfg.email_endjob() > 0: