mirror of
https://github.com/more-tech4-magnum-opus/backend.git
synced 2024-11-22 11:36:33 +03:00
43 lines
951 B
Bash
43 lines
951 B
Bash
#!/bin/bash
|
|
|
|
set -o errexit
|
|
set -o pipefail
|
|
set -o nounset
|
|
|
|
|
|
|
|
# N.B. If only .env files supported variable expansion...
|
|
export CELERY_BROKER_URL="${REDIS_URL}"
|
|
|
|
python << END
|
|
import sys
|
|
import time
|
|
|
|
import psycopg2
|
|
|
|
suggest_unrecoverable_after = 30
|
|
start = time.time()
|
|
|
|
while True:
|
|
try:
|
|
psycopg2.connect(
|
|
dbname="${POSTGRES_DB}",
|
|
user="${POSTGRES_USER}",
|
|
password="${POSTGRES_PASSWORD}",
|
|
host="${POSTGRES_HOST}",
|
|
port="${POSTGRES_PORT}",
|
|
)
|
|
break
|
|
except psycopg2.OperationalError as error:
|
|
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
|
|
|
|
>&2 echo 'PostgreSQL is available'
|
|
|
|
exec "$@"
|