- logger.debug("Executing cmd: %s", curl_cmd)
- subprocess.check_call(curl_cmd, shell=True)
+ count = 0
+ delay = 10
+ max_tries = 10
+ while True:
+ count += 1
+
+ logger.debug("Executing cmd: %s", curl_cmd)
+ proc = subprocess.Popen(curl_cmd, shell=True,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+
+ proc.wait()
+ logger.debug("Process: {}".format(proc))
+
+ if proc.returncode == 0:
+ # Check if response is 200 OK
+ logger.info("Got success response")
+ break
+
+ elif proc.returncode == 7:
+ # Connection timeout
+ if count >= max_tries:
+ logger.error("Connect failed for {}. Failing".format(count))
+ break
+ # Try after delay
+ time.sleep(delay)
+ else:
+ #Exit the loop incase of errors other than connection timeout and response ok
+ err_resp = proc.stderr.read().decode()
+ logger.error("Got error response: {}".format(err_resp))
+ return proc.returncode
+
+ return proc.returncode