Skip to content

Commit

Permalink
Add retry logic to pg_restore
Browse files Browse the repository at this point in the history
Resolves #26
  • Loading branch information
c-w committed Aug 24, 2018
1 parent fefcbdf commit 43d8ddc
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

set -e

run_sql() {
PGSSLMODE="require" \
PGPASSWORD="${FEATURES_DB_PASSWORD}" \
Expand Down Expand Up @@ -72,14 +74,26 @@ if ! features_database_exists; then
< /app/ddl/schema.sql run_sql "${FEATURES_DB_NAME}"
log "...done, schema is now set up"

log "Fetching database dump..."
curl --silent "${FEATURES_DB_DUMP_URL}" > "${dump_file}"
log "...done, database dump is now available"

log "Ingesting database dump..."
load_features_dump "${dump_file}"
retries=0
max_retries=5
db_is_setup=0
while [ "${retries}" -lt "${max_retries}" ]; do
log "Fetching database dump..."
curl --silent "${FEATURES_DB_DUMP_URL}" > "${dump_file}"
log "...done, database dump is now available"

log "Ingesting database dump..."
if load_features_dump "${dump_file}"; then
log "...done, database dump is now ingested"
db_is_setup=1
break
else
retries="$((retries + 1))"
log "...error ingesting database dump, retrying"
fi
done
if [ "${db_is_setup}" -ne 1 ]; then fail "Unable to setup database in ${max_retries} retries"; fi
rm "${dump_file}"
log "...done, database dump is now ingested"

log "Setting up indices..."
< /app/ddl/indices.sql run_sql "${FEATURES_DB_NAME}"
Expand Down

0 comments on commit 43d8ddc

Please sign in to comment.