Skip to content

Commit

Permalink
add DATABASE_URL export to celery scripts (#1402)
Browse files Browse the repository at this point in the history
  • Loading branch information
sainak authored Jun 21, 2023
1 parent c1a02aa commit 5ac8ab1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
3 changes: 3 additions & 0 deletions celery_beat-ecs.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/bin/bash

if [ -z "${DATABASE_URL}" ]; then
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
fi
celery --app=config.celery_app beat --loglevel=info
5 changes: 5 additions & 0 deletions celery_beat.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
#!/bin/bash

if [ -z "${DATABASE_URL}" ]; then
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
fi
export NEW_RELIC_CONFIG_FILE=/etc/newrelic.ini
newrelic-admin run-program celery --app=config.celery_app beat --loglevel=info
3 changes: 3 additions & 0 deletions celery_worker-ecs.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/bin/bash

if [ -z "${DATABASE_URL}" ]; then
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
fi
celery --app=config.celery_app worker --max-tasks-per-child=6 --loglevel=info
5 changes: 5 additions & 0 deletions celery_worker.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
#!/bin/bash

if [ -z "${DATABASE_URL}" ]; then
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
fi
export NEW_RELIC_CONFIG_FILE=/etc/newrelic.ini
newrelic-admin run-program celery --app=config.celery_app worker --max-tasks-per-child=6 --loglevel=info
14 changes: 3 additions & 11 deletions start
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ set -o errexit
set -o pipefail
set -o nounset

if [ -z "${POSTGRES_USER}" ]; then
base_postgres_image_default_user='postgres'
export POSTGRES_USER="${base_postgres_image_default_user}"
if [ -z "${DATABASE_URL}" ]; then
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
fi
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"

postgres_ready() {
python << END
Expand All @@ -17,13 +15,7 @@ import sys
import psycopg
try:
psycopg.connect(
dbname="${POSTGRES_DB}",
user="${POSTGRES_USER}",
password="${POSTGRES_PASSWORD}",
host="${POSTGRES_HOST}",
port="${POSTGRES_PORT}",
)
psycopg.connect(conninfo="${DATABASE_URL}")
except psycopg.OperationalError:
sys.exit(-1)
sys.exit(0)
Expand Down
15 changes: 4 additions & 11 deletions start-ecs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ set -o errexit
set -o pipefail
set -o nounset

if [ -z "${POSTGRES_USER}" ]; then
base_postgres_image_default_user='postgres'
export POSTGRES_USER="${base_postgres_image_default_user}"
if [ -z "${DATABASE_URL}" ]; then
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
fi
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"

postgres_ready() {
python << END
Expand All @@ -17,19 +15,14 @@ import sys
import psycopg
try:
psycopg.connect(
dbname="${POSTGRES_DB}",
user="${POSTGRES_USER}",
password="${POSTGRES_PASSWORD}",
host="${POSTGRES_HOST}",
port="${POSTGRES_PORT}",
)
psycopg.connect(conninfo="${DATABASE_URL}")
except psycopg.OperationalError:
sys.exit(-1)
sys.exit(0)
END
}

until postgres_ready; do
>&2 echo 'Waiting for PostgreSQL to become available...'
sleep 1
Expand Down

0 comments on commit 5ac8ab1

Please sign in to comment.