Debian Codegraph @

test_haystack/solr_tests/server/wait-for-solr

raw
1 #!/usr/bin/env python
2 """Simple throttle to wait for Solr to start on busy test servers"""
3 import sys
4 import time
5
6 import requests
7
8 max_retries = 100
9 retry_count = 0
10 retry_delay = 15
11 status_url = "http://localhost:9001/solr/collection1/admin/ping"
12
13
14 while retry_count < max_retries:
15 status_code = 0
16
17 try:
18 r = requests.get(status_url)
19 status_code = r.status_code
20 if status_code == 200:
21 sys.exit(0)
22 except Exception as exc:
23 print(
24 "Unhandled exception requesting %s: %s" % (status_url, exc), file=sys.stderr
25 )
26
27 retry_count += 1
28
29 print(
30 "Waiting {0} seconds for Solr to start (retry #{1}, status {2})".format(
31 retry_delay, retry_count, status_code
32 ),
33 file=sys.stderr,
34 )
35 time.sleep(retry_delay)
36
37
38 print("Solr took too long to start (#%d retries)" % retry_count, file=sys.stderr)
39 sys.exit(1)