From aa7c6931bb5384dd04a2d27e0d48879242ed98be Mon Sep 17 00:00:00 2001 From: Ovler Date: Wed, 19 Jun 2024 13:22:16 +0000 Subject: [PATCH 1/5] fix: handle upload failures and retry --- biliarchiver/_biliarchiver_upload_bvid.py | 28 +++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/biliarchiver/_biliarchiver_upload_bvid.py b/biliarchiver/_biliarchiver_upload_bvid.py index 09dd1c1..0cb61c1 100644 --- a/biliarchiver/_biliarchiver_upload_bvid.py +++ b/biliarchiver/_biliarchiver_upload_bvid.py @@ -232,15 +232,25 @@ def _upload_bvid( print(md) if filedict: - r = item.upload( - files=filedict, - metadata=md, - access_key=access_key, - secret_key=secret_key, - verbose=True, - queue_derive=True, - retries=5, - ) + upload_retry = 5 + while upload_retry > 0: + try: + r = item.upload( + files=filedict, + metadata=md, + access_key=access_key, + secret_key=secret_key, + verbose=True, + queue_derive=True, + retries=5, + ) + break + except Exception as e: + print(e) + upload_retry -= 1 + print(f"Upload failed, retrying ({upload_retry}) ...") + time.sleep(30) + assert upload_retry > 0, "Upload failed" tries = 100 item = get_item(remote_identifier) # refresh item From 4f318e2ba1eb39ab3637df3fc1d85bdd8345090e Mon Sep 17 00:00:00 2001 From: Ovler Date: Wed, 19 Jun 2024 13:32:22 +0000 Subject: [PATCH 2/5] chore: wait longer and longer --- biliarchiver/_biliarchiver_upload_bvid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/biliarchiver/_biliarchiver_upload_bvid.py b/biliarchiver/_biliarchiver_upload_bvid.py index 0cb61c1..0bec59c 100644 --- a/biliarchiver/_biliarchiver_upload_bvid.py +++ b/biliarchiver/_biliarchiver_upload_bvid.py @@ -249,7 +249,7 @@ def _upload_bvid( print(e) upload_retry -= 1 print(f"Upload failed, retrying ({upload_retry}) ...") - time.sleep(30) + time.sleep(30 * (5 - upload_retry)) assert upload_retry > 0, "Upload failed" tries = 100 From d0245fde8ea365c8654362e309e18088be397ed1 Mon Sep 17 00:00:00 2001 From: Ovler Date: Wed, 19 Jun 2024 13:41:47 +0000 Subject: [PATCH 3/5] chore: 30 is not enough for IA to be good again --- biliarchiver/_biliarchiver_upload_bvid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/biliarchiver/_biliarchiver_upload_bvid.py b/biliarchiver/_biliarchiver_upload_bvid.py index 0bec59c..87b3f36 100644 --- a/biliarchiver/_biliarchiver_upload_bvid.py +++ b/biliarchiver/_biliarchiver_upload_bvid.py @@ -249,7 +249,7 @@ def _upload_bvid( print(e) upload_retry -= 1 print(f"Upload failed, retrying ({upload_retry}) ...") - time.sleep(30 * (5 - upload_retry)) + time.sleep(30 * (6 - upload_retry)) assert upload_retry > 0, "Upload failed" tries = 100 From 9e4f251a2b1e484ba2a47aed484717dc4b2470d5 Mon Sep 17 00:00:00 2001 From: yzqzss <30341059+yzqzss@users.noreply.github.com> Date: Thu, 20 Jun 2024 00:49:30 +0800 Subject: [PATCH 4/5] Update _biliarchiver_upload_bvid.py --- biliarchiver/_biliarchiver_upload_bvid.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/biliarchiver/_biliarchiver_upload_bvid.py b/biliarchiver/_biliarchiver_upload_bvid.py index 87b3f36..034858d 100644 --- a/biliarchiver/_biliarchiver_upload_bvid.py +++ b/biliarchiver/_biliarchiver_upload_bvid.py @@ -233,7 +233,7 @@ def _upload_bvid( if filedict: upload_retry = 5 - while upload_retry > 0: + while upload_retry >= 0: try: r = item.upload( files=filedict, @@ -246,11 +246,12 @@ def _upload_bvid( ) break except Exception as e: - print(e) upload_retry -= 1 + print(e) + if upload_retry < 0: + raise e print(f"Upload failed, retrying ({upload_retry}) ...") - time.sleep(30 * (6 - upload_retry)) - assert upload_retry > 0, "Upload failed" + time.sleep(min(30 * (6 - upload_retry), 240)) tries = 100 item = get_item(remote_identifier) # refresh item From 1c0870e7bc8e0fb56abf72a247fffaa0cadb2350 Mon Sep 17 00:00:00 2001 From: Ovler Date: Thu, 20 Jun 2024 02:40:33 +0000 Subject: [PATCH 5/5] chore: only retry if EOF or SSL error --- biliarchiver/_biliarchiver_upload_bvid.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/biliarchiver/_biliarchiver_upload_bvid.py b/biliarchiver/_biliarchiver_upload_bvid.py index 034858d..163fd44 100644 --- a/biliarchiver/_biliarchiver_upload_bvid.py +++ b/biliarchiver/_biliarchiver_upload_bvid.py @@ -246,13 +246,16 @@ def _upload_bvid( ) break except Exception as e: - upload_retry -= 1 - print(e) - if upload_retry < 0: + if "EOF" in str(e) or "SSL" in str(e): + upload_retry -= 1 + print(e) + if upload_retry < 0: + raise e + print(f"Upload failed, retrying ({upload_retry}) ...") + time.sleep(min(30 * (6 - upload_retry), 240)) + continue + else: raise e - print(f"Upload failed, retrying ({upload_retry}) ...") - time.sleep(min(30 * (6 - upload_retry), 240)) - tries = 100 item = get_item(remote_identifier) # refresh item while not item.exists and tries > 0: