Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portable database health check #70

Merged
merged 2 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions tools/docker-compose/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ services:
context: $PWD
dockerfile: wisdom-service.Containerfile
depends_on:
redis:
condition: service_started
db:
condition: service_healthy
- redis
- db
restart: always
volumes:
- $PWD/ansible_wisdom:/var/www/ansible_wisdom
Expand Down Expand Up @@ -43,8 +41,6 @@ services:
- POSTGRES_DB=wisdom
- POSTGRES_USER=wisdom
restart: always
healthcheck:
test: pg_isready -U wisdom
networks:
- dbnet
# Disabled because this doesn't work properly on MacOS.
Expand Down
20 changes: 20 additions & 0 deletions tools/scripts/launch-wisdom.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
#!/bin/bash
set -o errexit

database_ready() {
/var/www/venv/bin/python ansible_wisdom/manage.py shell <<EOF
import sys
from django.db import connection

try:
connection.ensure_connection()
except Exception:
sys.exit(1)
EOF
}

until database_ready
do
echo "Waiting until the database is ready..."
sleep 5
Copy link
Contributor

@gebhardtr gebhardtr Feb 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to factor this sleep out of the loop and add it as a criterion in the probe? ("keep running launch_wisdom until it succeeds"?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both ways seem equivalent to me.

done

/var/www/venv/bin/python ansible_wisdom/manage.py migrate --noinput

cd ansible_wisdom/
Expand Down