This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/util/wait_for_endpoints.py
Jimmy Zelinskie 1f420b82f6 conf/init: add startup dependencies on pushgateway
Many processes should not start until the pushgateway has come online
and is ready to serve traffic. This change adds a simple loop in the run
command in order to spinlock until this condition as been met.
2019-11-21 12:53:09 -05:00

22 lines
580 B
Python

from argparse import ArgumentParser
from contextlib import closing
from time import sleep
import requests
def main():
parser = ArgumentParser(description="block until the given endpoints return 200")
parser.add_argument('endpoints', type=str, nargs='+', help='the endpoints to wait for')
for endpoint in parser.parse_args().endpoints:
listening = False
while not listening:
try:
listening = requests.get(endpoint).status_code == 200
except requests.exceptions.ConnectionError:
pass
sleep(1)
if __name__ == '__main__':
main()