mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-07-22 13:59:47 +03:00
46 lines
973 B
Bash
46 lines
973 B
Bash
#!/bin/bash
|
|
|
|
set -o errexit
|
|
set -o nounset
|
|
|
|
|
|
rm -f './celerybeat.pid'
|
|
|
|
postgres_ready() {
|
|
python << END
|
|
import sys
|
|
import psycopg2
|
|
try:
|
|
conn = psycopg2.connect(
|
|
dbname="${POSTGRES_DB}",
|
|
user="${POSTGRES_USER}",
|
|
password="${POSTGRES_PASSWORD}",
|
|
host="${POSTGRES_HOST}",
|
|
port="${POSTGRES_PORT}",
|
|
)
|
|
# Check if table exists yet.
|
|
# If not, wait for docker-compose up to migrate all tables.
|
|
cur = conn.cursor()
|
|
cur.execute(
|
|
"select exists(select * from information_schema.tables where table_name=%s)",
|
|
('django_celery_beat_periodictask',)
|
|
)
|
|
if cur.fetchone()[0] == 1:
|
|
cur.close()
|
|
sys.exit(0)
|
|
else:
|
|
cur.close()
|
|
sys.exit(-1)
|
|
except psycopg2.OperationalError:
|
|
sys.exit(-1)
|
|
|
|
END
|
|
}
|
|
until postgres_ready; do
|
|
>&2 echo 'Waiting for celerybeat models to be migrated...'
|
|
sleep 1
|
|
done
|
|
>&2 echo 'PostgreSQL is ready'
|
|
|
|
celery -A config.celery_app beat -l INFO
|