From ff9633d189ba37aa8c80cd8d168cc259f5ba21b3 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Fri, 12 Aug 2022 17:46:27 +0200 Subject: Raise Static Build After Waiting Adds a missing raise in the static build for situations where everything was successful, but the build time passed the deadline specified by the site API. Signed-off-by: Hassan Abouelela --- static-builds/netlify_build.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'static-builds/netlify_build.py') diff --git a/static-builds/netlify_build.py b/static-builds/netlify_build.py index a473bd91..7143a19a 100644 --- a/static-builds/netlify_build.py +++ b/static-builds/netlify_build.py @@ -15,6 +15,18 @@ from urllib import parse import httpx + +def raise_response(response: httpx.Response) -> None: + """Raise an exception from a response if necessary.""" + if response.status_code // 100 != 2: + try: + print(response.json()) + except json.JSONDecodeError: + pass + + response.raise_for_status() + + if __name__ == "__main__": owner, repo = parse.urlparse(os.getenv("REPOSITORY_URL")).path.lstrip("/").split("/")[0:2] @@ -29,14 +41,7 @@ if __name__ == "__main__": ]) print(f"Fetching download URL from {download_url}") response = httpx.get(download_url, follow_redirects=True) - - if response.status_code // 100 != 2: - try: - print(response.json()) - except json.JSONDecodeError: - pass - - response.raise_for_status() + raise_response(response) # The workflow is still pending, retry in a bit while response.status_code == 202: @@ -44,6 +49,7 @@ if __name__ == "__main__": time.sleep(10) response = httpx.get(download_url, follow_redirects=True) + raise_response(response) url = response.json()["url"] print(f"Downloading build from {url}") zipped_content = httpx.get(url, follow_redirects=True) -- cgit v1.2.3 From 3335cc6c710f028e0e2303a7fa9dae5bd4220d6e Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Fri, 12 Aug 2022 22:56:51 +0200 Subject: Increase Timeout For Artifact Download Sets the timeout of downloads to 3 minutes (from a default of 5 seconds) since some artifacts can be quite large. Signed-off-by: Hassan Abouelela --- static-builds/netlify_build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'static-builds/netlify_build.py') diff --git a/static-builds/netlify_build.py b/static-builds/netlify_build.py index 7143a19a..f3a53f72 100644 --- a/static-builds/netlify_build.py +++ b/static-builds/netlify_build.py @@ -52,7 +52,7 @@ if __name__ == "__main__": raise_response(response) url = response.json()["url"] print(f"Downloading build from {url}") - zipped_content = httpx.get(url, follow_redirects=True) + zipped_content = httpx.get(url, follow_redirects=True, timeout=3 * 60) zipped_content.raise_for_status() zip_file = Path("temp.zip") -- cgit v1.2.3