mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-30 05:24:01 +03:00
Provide more context when wating for PostgreSQL takes too long (#3782)
This commit is contained in:
parent
119a282dad
commit
903fe45eca
|
@ -16,13 +16,17 @@ if [ -z "${POSTGRES_USER}" ]; then
|
||||||
fi
|
fi
|
||||||
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
|
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
|
||||||
|
|
||||||
postgres_ready() {
|
|
||||||
python << END
|
python << END
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
import psycopg2
|
import psycopg2
|
||||||
|
|
||||||
try:
|
suggest_unrecoverable_after = 30
|
||||||
|
start = time.time()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
psycopg2.connect(
|
psycopg2.connect(
|
||||||
dbname="${POSTGRES_DB}",
|
dbname="${POSTGRES_DB}",
|
||||||
user="${POSTGRES_USER}",
|
user="${POSTGRES_USER}",
|
||||||
|
@ -30,16 +34,16 @@ try:
|
||||||
host="${POSTGRES_HOST}",
|
host="${POSTGRES_HOST}",
|
||||||
port="${POSTGRES_PORT}",
|
port="${POSTGRES_PORT}",
|
||||||
)
|
)
|
||||||
except psycopg2.OperationalError:
|
break
|
||||||
sys.exit(-1)
|
except psycopg2.OperationalError as error:
|
||||||
sys.exit(0)
|
sys.stderr.write("Waiting for PostgreSQL to become available...\n")
|
||||||
|
|
||||||
|
if time.time() - start > suggest_unrecoverable_after:
|
||||||
|
sys.stderr.write(" This is taking longer than expected. The following exception may be indicative of an unrecoverable error: '{}'\n".format(error))
|
||||||
|
|
||||||
|
time.sleep(1)
|
||||||
END
|
END
|
||||||
}
|
|
||||||
until postgres_ready; do
|
|
||||||
>&2 echo 'Waiting for PostgreSQL to become available...'
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
>&2 echo 'PostgreSQL is available'
|
>&2 echo 'PostgreSQL is available'
|
||||||
|
|
||||||
exec "$@"
|
exec "$@"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user