#!/usr/bin/env python3 import argparse import time from urllib.request import urlopen p = argparse.ArgumentParser() p.add_argument('--base-url', default='http://localhost:8080') args = p.parse_args() deadline = time.monotonic()+90 while True: try: with urlopen(args.base_url+'/health/ready', timeout=3) as response: if response.status == 200: print('API ready') break except OSError: pass if time.monotonic() >= deadline: raise SystemExit('API did not become ready in 90 seconds') time.sleep(0.5)