szurubooru/server/wait-for-es
2018-07-25 13:39:57 +02:00

33 lines
856 B
Python
Executable file

#!/usr/bin/env python3
'''
Docker helper script. Blocks until the ElasticSearch service is ready.
'''
import logging
import time
import elasticsearch
from szurubooru import config, errors
def main():
print('Looking for ElasticSearch connection...')
logging.basicConfig(level=logging.ERROR)
es = elasticsearch.Elasticsearch([{
'host': config.config['elasticsearch']['host'],
'port': config.config['elasticsearch']['port'],
}])
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()