From 12528186f45b8d1e8e72e22a4462f9654dc1efdd Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Thu, 11 Jul 2024 10:19:40 -0700 Subject: [PATCH] pw: retry check posts When patchwork gets slow everything fails. Try 2 times before crashing. Signed-off-by: Jakub Kicinski --- pw/patchwork.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pw/patchwork.py b/pw/patchwork.py index bd01347..1c30f3a 100644 --- a/pw/patchwork.py +++ b/pw/patchwork.py @@ -9,6 +9,7 @@ import requests from requests.adapters import HTTPAdapter from requests.packages.urllib3.util.retry import Retry +import time import urllib import core @@ -125,7 +126,10 @@ def _post(self, req, headers, data, api='1.1'): core.log("Headers", headers) core.log("Data", data) core.log("Response", ret) - core.log("Response data", ret.json()) + try: + core.log("Response data", ret.json()) + except json.decoder.JSONDecodeError: + core.log("Response data", ret.content.decode()) finally: core.log_end_sec() @@ -189,6 +193,10 @@ def post_check(self, patch, name, state, url, desc): } r = self._post(f'patches/{patch}/checks/', headers=headers, data=data) + if r.status_code == 502 or r.status_code == 504: + # Timeout, let's wait 30 sec and retry, POST isn't retried by the lib. + time.sleep(30) + r = self._post(f'patches/{patch}/checks/', headers=headers, data=data) if r.status_code != 201: raise PatchworkPostException(r)