server/facade: integrated elasticsearch wait into entrypoint
This commit is contained in:
parent
fa3b6275b3
commit
dd56c287b5
3 changed files with 3 additions and 34 deletions
|
@ -25,7 +25,6 @@ RUN \
|
||||||
echo "#!/bin/sh" >> /init && \
|
echo "#!/bin/sh" >> /init && \
|
||||||
echo "set -e" >> /init && \
|
echo "set -e" >> /init && \
|
||||||
echo "cd /opt/app" >> /init && \
|
echo "cd /opt/app" >> /init && \
|
||||||
echo "./wait-for-es" >> /init && \
|
|
||||||
echo "alembic upgrade head" >> /init && \
|
echo "alembic upgrade head" >> /init && \
|
||||||
echo "exec waitress-serve --port ${PORT} szurubooru.facade:app" \
|
echo "exec waitress-serve --port ${PORT} szurubooru.facade:app" \
|
||||||
>> /init && \
|
>> /init && \
|
||||||
|
|
|
@ -8,7 +8,7 @@ import coloredlogs
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
import sqlalchemy.orm.exc
|
import sqlalchemy.orm.exc
|
||||||
from szurubooru import config, db, errors, rest
|
from szurubooru import config, db, errors, rest
|
||||||
from szurubooru.func import posts, file_uploads
|
from szurubooru.func import posts, file_uploads, image_hash
|
||||||
# pylint: disable=unused-import
|
# pylint: disable=unused-import
|
||||||
from szurubooru import api, middleware
|
from szurubooru import api, middleware
|
||||||
|
|
||||||
|
@ -130,6 +130,8 @@ def create_app() -> Callable[[Any, Any], Any]:
|
||||||
purge_thread.start()
|
purge_thread.start()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
image_hash.get_session().cluster.health(
|
||||||
|
wait_for_status='yellow', request_timeout=30)
|
||||||
posts.populate_reverse_search()
|
posts.populate_reverse_search()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
except errors.ThirdPartyError:
|
except errors.ThirdPartyError:
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
#!/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()
|
|
Loading…
Reference in a new issue