Skip to content

Commit

Permalink
Merge pull request #353 from truenas/NAS-113492
Browse files Browse the repository at this point in the history
NAS-113492 / 22.02 / Add readable message on connection error
  • Loading branch information
Qubad786 authored Dec 28, 2021
2 parents a071495 + 24253cd commit ea74589
Showing 1 changed file with 43 additions and 34 deletions.
77 changes: 43 additions & 34 deletions iocage_lib/ioc_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,40 +710,49 @@ def fetch_download(self, _list, missing=False):
dl_progress = 0
last_progress = 0

for i, chunk in enumerate(
r.iter_content(chunk_size=chunk_size), 1
):
if chunk:
elapsed = time.time() - start
dl_progress += len(chunk)
txz.write(chunk)

progress = float(i) / float(total)
if progress >= 1.:
progress = 1
progress = round(progress * 100, 0)

if progress != last_progress:
text = self.update_progress(
progress,
f'Downloading: {f}',
elapsed,
chunk_size
)

if progress % 10 == 0:
# Not for user output, but for callback
# heartbeats
iocage_lib.ioc_common.logit(
{
'level': 'INFO',
'message': text.rstrip()
},
_callback=self.callback,
silent=True)

last_progress = progress
start = time.time()
try:
for i, chunk in enumerate(
r.iter_content(chunk_size=chunk_size), 1
):
if chunk:
elapsed = time.time() - start
dl_progress += len(chunk)
txz.write(chunk)

progress = float(i) / float(total)
if progress >= 1.:
progress = 1
progress = round(progress * 100, 0)

if progress != last_progress:
text = self.update_progress(
progress,
f'Downloading: {f}',
elapsed,
chunk_size
)

if progress % 10 == 0:
# Not for user output, but for callback
# heartbeats
iocage_lib.ioc_common.logit(
{
'level': 'INFO',
'message': text.rstrip()
},
_callback=self.callback,
silent=True)

last_progress = progress
start = time.time()
except requests.exceptions.ChunkedEncodingError as exc:
iocage_lib.ioc_common.logit(
{
"level": "EXCEPTION",
"message": f"Please check your internet connection. Details: {exc}",
},
_callback=self.callback
)

def update_progress(self, progress, display_text, elapsed, chunk_size):
"""
Expand Down

0 comments on commit ea74589

Please sign in to comment.