szurubooru/server/wait-for-es

32 lines
743 B
Python
Executable file

#!/usr/bin/env python3
'''
Docker helper script. Blocks until the ElasticSearch service is ready.
'''
import logging
import time
from szurubooru import errors
from szurubooru.func.image_hash import get_session
def main():
print('Looking for ElasticSearch connection...')
logging.basicConfig(level=logging.ERROR)
es = get_session()
TIMEOUT = 30
DELAY = 0.1
for _ in range(int(TIMEOUT / DELAY)):
try:
es.cluster.health(wait_for_status='yellow')
print('Connected to ElasticSearch!')
return
except Exception:
time.sleep(DELAY)
pass
raise errors.ThirdPartyError('Error connecting to ElasticSearch')
if __name__ == '__main__':
main()