From bed0308a78d70473479079212970cc6a6a481eb5 Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Sat, 25 Jun 2022 22:47:18 +0200 Subject: [PATCH 1/4] Add retry logic to 'Download Miniforge' step of win pipeline --- .../templates/azure-pipelines-win.yml.tmpl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/conda_smithy/templates/azure-pipelines-win.yml.tmpl b/conda_smithy/templates/azure-pipelines-win.yml.tmpl index 4389c200e..edd51f068 100644 --- a/conda_smithy/templates/azure-pipelines-win.yml.tmpl +++ b/conda_smithy/templates/azure-pipelines-win.yml.tmpl @@ -27,9 +27,22 @@ jobs: scriptSource: inline script: | import urllib.request + import time url = 'https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-Windows-x86_64.exe' path = r"$(Build.ArtifactStagingDirectory)/Miniforge.exe" - urllib.request.urlretrieve(url, path) + retry_time = 2 + retries = 5 + while retries >= 0: + retries -= 1 + try: + urllib.request.urlretrieve(url, path) + except urllib.error.URLError as e: + if retries >= 0: + print(f"Encountered error: '{e}'. Retry in {retry_time} seconds.") + time.sleep(retry_time) + retry_time *= 2 + else: + raise e - script: | start /wait "" %BUILD_ARTIFACTSTAGINGDIRECTORY%\Miniforge.exe /InstallationType=JustMe /RegisterPython=0 /S /D=C:\Miniforge From 14b262651a29c65f49762506525fdec635c0bf0e Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Sat, 25 Jun 2022 22:55:17 +0200 Subject: [PATCH 2/4] Add a news entry --- news/add-retry-logic.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 news/add-retry-logic.rst diff --git a/news/add-retry-logic.rst b/news/add-retry-logic.rst new file mode 100644 index 000000000..6aab3210d --- /dev/null +++ b/news/add-retry-logic.rst @@ -0,0 +1,4 @@ +**Added:** + +* The 'Download Miniforge' stage of the Windows pipeline now retries in case + of a download error. From af295e9ac00f166e39ee3138d2ac3f51d1ef41a6 Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Sun, 24 Jul 2022 11:56:22 +0200 Subject: [PATCH 3/4] Add ssl.SSLError to retry exceptions --- conda_smithy/templates/azure-pipelines-win.yml.tmpl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/conda_smithy/templates/azure-pipelines-win.yml.tmpl b/conda_smithy/templates/azure-pipelines-win.yml.tmpl index edd51f068..9503b87f8 100644 --- a/conda_smithy/templates/azure-pipelines-win.yml.tmpl +++ b/conda_smithy/templates/azure-pipelines-win.yml.tmpl @@ -28,6 +28,7 @@ jobs: script: | import urllib.request import time + import ssl url = 'https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-Windows-x86_64.exe' path = r"$(Build.ArtifactStagingDirectory)/Miniforge.exe" retry_time = 2 @@ -36,7 +37,7 @@ jobs: retries -= 1 try: urllib.request.urlretrieve(url, path) - except urllib.error.URLError as e: + except (urllib.error.URLError, ssl.SSLError) as e: if retries >= 0: print(f"Encountered error: '{e}'. Retry in {retry_time} seconds.") time.sleep(retry_time) From 46cdbce2c22b1775c5fa9797f5f0158aa635af65 Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Sun, 24 Jul 2022 12:01:26 +0200 Subject: [PATCH 4/4] Improve variable names and lint --- .../templates/azure-pipelines-win.yml.tmpl | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/conda_smithy/templates/azure-pipelines-win.yml.tmpl b/conda_smithy/templates/azure-pipelines-win.yml.tmpl index 9503b87f8..9d4db277b 100644 --- a/conda_smithy/templates/azure-pipelines-win.yml.tmpl +++ b/conda_smithy/templates/azure-pipelines-win.yml.tmpl @@ -26,19 +26,20 @@ jobs: inputs: scriptSource: inline script: | - import urllib.request - import time import ssl - url = 'https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-Windows-x86_64.exe' - path = r"$(Build.ArtifactStagingDirectory)/Miniforge.exe" + import time + import urllib.error + import urllib.request + url = r"https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-Windows-x86_64.exe" + destination_path = r"$(Build.ArtifactStagingDirectory)/Miniforge.exe" retry_time = 2 - retries = 5 - while retries >= 0: - retries -= 1 + tries_remaining = 5 + while tries_remaining >= 0: + tries_remaining -= 1 try: - urllib.request.urlretrieve(url, path) + urllib.request.urlretrieve(url, destination_path) except (urllib.error.URLError, ssl.SSLError) as e: - if retries >= 0: + if tries_remaining >= 0: print(f"Encountered error: '{e}'. Retry in {retry_time} seconds.") time.sleep(retry_time) retry_time *= 2