File: wait-for-solr

package info (click to toggle)
django-haystack 3.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,504 kB
  • sloc: python: 23,475; xml: 1,708; sh: 74; makefile: 71
file content (39 lines) | stat: -rwxr-xr-x 915 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
"""Simple throttle to wait for Solr to start on busy test servers"""
import sys
import time

import requests

max_retries = 100
retry_count = 0
retry_delay = 15
status_url = "http://localhost:9001/solr/collection1/admin/ping"


while retry_count < max_retries:
    status_code = 0

    try:
        r = requests.get(status_url)
        status_code = r.status_code
        if status_code == 200:
            sys.exit(0)
    except Exception as exc:
        print(
            "Unhandled exception requesting %s: %s" % (status_url, exc), file=sys.stderr
        )

    retry_count += 1

    print(
        "Waiting {0} seconds for Solr to start (retry #{1}, status {2})".format(
            retry_delay, retry_count, status_code
        ),
        file=sys.stderr,
    )
    time.sleep(retry_delay)


print("Solr took too long to start (#%d retries)" % retry_count, file=sys.stderr)
sys.exit(1)