Skip to content

Commit cfaf2fd

Browse files
committed
make retry loop more robust
1 parent d903ab6 commit cfaf2fd

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

zap/src/zap.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,20 @@ def zap_shutdown():
7171
logging.info("Attempting to shutdown ZAP")
7272
apikey = os.getenv("ZAP_API_KEY", "")
7373
zap = ZAPv2(proxies={"http": PROXY, "https": PROXY}, apikey=apikey)
74-
try:
75-
sleep_time = 20
76-
attempts = int((TIMEOUT_MINS*60)/20)
77-
for _ in range(attempts):
74+
sleep_time = 20
75+
attempts = int((TIMEOUT_MINS*60)/20)
76+
for attempt in range(attempts):
77+
try:
7878
shutdown_endpoint = zap.base + "core/action/shutdown/"
7979
headers = { "X-ZAP-API-Key" : apikey }
8080
resp = requests.get(shutdown_endpoint, proxies=proxies, headers=headers,
8181
timeout=int(TIMEOUT_MINS*60)/2)
8282
logging.info(f"Response code from requesting ZAP shutdown: {resp.status_code}")
8383
if int(resp.status_code) == 200:
84-
break
85-
time.sleep(sleep_time)
86-
87-
except Exception as e:
88-
logging.error("failed to shut down zap.")
89-
logging.error(e)
90-
84+
return
85+
except Exception as e:
86+
logging.error(f"An error occured while shutting down zap. Attempt {attempt+1}")
87+
time.sleep(sleep_time)
9188

9289
def parse_url(url):
9390
"""

0 commit comments

Comments
 (0)